Logo AND Algorithmique Numérique Distribuée

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