Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SIMIX_process_change_host becomes ActorImpl::change_host
[simgrid.git] / src / simix / smx_private.hpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMIX_PRIVATE_HPP
7 #define SIMIX_PRIVATE_HPP
8
9 #include "simgrid/s4u/Actor.hpp"
10 #include "src/kernel/context/Context.hpp"
11 #include "src/simix/ActorImpl.hpp"
12
13 #include <boost/intrusive/list.hpp>
14 #include <mutex>
15 #include <unordered_map>
16 #include <vector>
17
18 /********************************** Simix Global ******************************/
19
20 namespace simgrid {
21 namespace simix {
22
23 class Global {
24   friend XBT_PUBLIC bool simgrid::s4u::this_actor::is_maestro();
25
26 public:
27   smx_context_factory_t context_factory = nullptr;
28   std::vector<smx_actor_t> process_to_run;
29   std::vector<smx_actor_t> process_that_ran;
30   std::map<aid_t, smx_actor_t> process_list;
31   boost::intrusive::list<kernel::actor::ActorImpl,
32                          boost::intrusive::member_hook<kernel::actor::ActorImpl, boost::intrusive::list_member_hook<>,
33                                                        &kernel::actor::ActorImpl::smx_destroy_list_hook>>
34       process_to_destroy;
35 #if SIMGRID_HAVE_MC
36   /* MCer cannot read members process_list and process_to_destroy above in the remote process, so we copy the info it
37    * needs in a dynar.
38    * FIXME: This is supposed to be a temporary hack.
39    * A better solution would be to change the split between MCer and MCed, where the responsibility
40    *   to compute the list of the enabled transitions goes to the MCed.
41    * That way, the MCer would not need to have the list of actors on its side.
42    * These info could be published by the MCed to the MCer in a way inspired of vd.so
43    */
44   xbt_dynar_t actors_vector      = xbt_dynar_new(sizeof(smx_actor_t), nullptr);
45   xbt_dynar_t dead_actors_vector = xbt_dynar_new(sizeof(smx_actor_t), nullptr);
46 #endif
47   smx_actor_t maestro_process   = nullptr;
48
49   // Maps function names to actor code:
50   std::unordered_map<std::string, simgrid::simix::ActorCodeFactory> registered_functions;
51
52   // This might be used when no corresponding function name is registered:
53   simgrid::simix::ActorCodeFactory default_function;
54
55   std::mutex mutex;
56
57   std::vector<simgrid::xbt::Task<void()>> tasks;
58   std::vector<simgrid::xbt::Task<void()>> tasksTemp;
59
60   std::vector<simgrid::kernel::actor::ActorImpl*> daemons;
61 };
62 }
63 }
64
65 XBT_PUBLIC_DATA std::unique_ptr<simgrid::simix::Global> simix_global;
66
67 XBT_PUBLIC void SIMIX_clean();
68
69 /******************************** Exceptions *********************************/
70 /** @brief Ask to the provided ActorImpl to raise the provided exception */
71 #define SMX_EXCEPTION(issuer, cat, val, msg)                                                                           \
72   if (1) {                                                                                                             \
73     simgrid::kernel::actor::ActorImpl* _smx_throw_issuer = (issuer); /* evaluate only once */                          \
74     xbt_ex e(XBT_THROW_POINT, msg);                                                                                    \
75     e.category                   = cat;                                                                                \
76     e.value                      = val;                                                                                \
77     _smx_throw_issuer->exception = std::make_exception_ptr(e);                                                         \
78   } else                                                                                                               \
79     ((void)0)
80
81 #endif