Logo AND Algorithmique Numérique Distribuée

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