Logo AND Algorithmique Numérique Distribuée

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