Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a0c713eba7fb2b4691c6e1ab7c86f8ebb05bd3c6
[simgrid.git] / src / simix / smx_private.h
1 /* Copyright (c) 2007-2017. 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_H
7 #define SIMIX_PRIVATE_H
8
9 #include "simgrid/s4u/Actor.hpp"
10 #include "src/kernel/context/Context.hpp"
11 #include <signal.h>
12
13 #include <map>
14
15 /********************************** Simix Global ******************************/
16
17 namespace simgrid {
18 namespace simix {
19
20 class Global {
21   friend bool simgrid::s4u::this_actor::isMaestro();
22
23 public:
24   smx_context_factory_t context_factory = nullptr;
25   xbt_dynar_t process_to_run = nullptr;
26   xbt_dynar_t process_that_ran = nullptr;
27   std::map<aid_t, smx_actor_t> process_list;
28 #if SIMGRID_HAVE_MC
29   /* MCer cannot read the std::map above in the remote process, so we copy the info it needs in a dynar.
30    * FIXME: This is supposed to be a temporary hack.
31    * A better solution would be to change the split between MCer and MCed, where the responsibility
32    *   to compute the list of the enabled transitions goes to the MCed.
33    * That way, the MCer would not need to have the list of actors on its side.
34    * These info could be published by the MCed to the MCer in a way inspired of vd.so
35    */
36   xbt_dynar_t actors_vector = xbt_dynar_new(sizeof(smx_actor_t), nullptr);
37 #endif
38   xbt_swag_t process_to_destroy = nullptr;
39   smx_actor_t maestro_process = nullptr;
40
41   // Maps function names to actor code:
42   std::unordered_map<std::string, simgrid::simix::ActorCodeFactory> registered_functions;
43
44   // This might be used when no corresponding function name is registered:
45   simgrid::simix::ActorCodeFactory default_function;
46
47   smx_creation_func_t create_process_function = nullptr;
48   void_pfn_smxprocess_t kill_process_function = nullptr;
49   /** Callback used when killing a SMX_process */
50   void_pfn_smxprocess_t cleanup_process_function = nullptr;
51   xbt_os_mutex_t mutex = nullptr;
52
53   std::vector<simgrid::xbt::Task<void()>> tasks;
54   std::vector<simgrid::xbt::Task<void()>> tasksTemp;
55
56   std::vector<simgrid::simix::ActorImpl*> daemons;
57 };
58
59 }
60 }
61
62 SG_BEGIN_DECL()
63
64 XBT_PUBLIC_DATA(std::unique_ptr<simgrid::simix::Global>) simix_global;
65
66 XBT_PUBLIC(void) SIMIX_clean();
67
68 /******************************** Exceptions *********************************/
69 /** @brief Ask to the provided simix process to raise the provided exception */
70 #define SMX_EXCEPTION(issuer, cat, val, msg) \
71   if (1) { \
72   smx_actor_t _smx_throw_issuer = (issuer); /* evaluate only once */ \
73   xbt_ex e(XBT_THROW_POINT, msg); \
74   e.category = cat; \
75   e.value = val; \
76   _smx_throw_issuer->exception = std::make_exception_ptr(e); \
77   } else ((void)0)
78
79 SG_END_DECL()
80
81 #endif