Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e78326f6a8674195806a41c39a74602dd86be5c8
[simgrid.git] / src / simix / smx_private.h
1 /* Copyright (c) 2007-2010, 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef _SIMIX_PRIVATE_H
8 #define _SIMIX_PRIVATE_H
9
10 #include <functional>
11 #include <memory>
12 #include <unordered_map>
13 #include <vector>
14
15 #include <xbt/functional.hpp>
16
17 #include "src/internal_config.h"
18 #include "simgrid/simix.h"
19 #include "surf/surf.h"
20 #include "xbt/config.h"
21 #include "xbt/xbt_os_time.h"
22 #include "xbt/function_types.h"
23 #include "src/xbt/ex_interface.h"
24 #include "src/instr/instr_private.h"
25
26 #include <signal.h>
27 #include "src/kernel/context/Context.hpp"
28
29 /********************************** Simix Global ******************************/
30
31 namespace simgrid {
32 namespace simix {
33
34 class Global {
35 public:
36   smx_context_factory_t context_factory = nullptr;
37   xbt_dynar_t process_to_run = nullptr;
38   xbt_dynar_t process_that_ran = nullptr;
39   xbt_swag_t process_list = nullptr;
40   xbt_swag_t process_to_destroy = nullptr;
41   smx_actor_t maestro_process = nullptr;
42
43   // Maps function names to actor code:
44   std::unordered_map<std::string, simgrid::simix::ActorCodeFactory> registered_functions;
45
46   // This might be used when no corresponding function name is registered:
47   simgrid::simix::ActorCodeFactory default_function;
48
49   smx_creation_func_t create_process_function = nullptr;
50   void_pfn_smxprocess_t kill_process_function = nullptr;
51   /** Callback used when killing a SMX_process */
52   void_pfn_smxprocess_t cleanup_process_function = nullptr;
53   xbt_os_mutex_t mutex = nullptr;
54
55   std::vector<simgrid::xbt::Task<void()>> tasks;
56   std::vector<simgrid::xbt::Task<void()>> tasksTemp;
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 /* ******************************** File ************************************ */
80 typedef struct s_smx_file {
81   surf_file_t surf_file;
82   void* data;                   /**< @brief user data */
83 } s_smx_file_t;
84
85
86 SG_END_DECL()
87
88 #endif