Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename smx_process_t to smx_actor_t
[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/base.h"
21 #include "xbt/fifo.h"
22 #include "xbt/swag.h"
23 #include "xbt/dict.h"
24 #include "xbt/mallocator.h"
25 #include "xbt/config.h"
26 #include "xbt/xbt_os_time.h"
27 #include "xbt/function_types.h"
28 #include "src/xbt/ex_interface.h"
29 #include "src/instr/instr_private.h"
30 #include "smx_host_private.h"
31 #include "smx_io_private.h"
32 #include "smx_network_private.h"
33 #include "popping_private.h"
34 #include "smx_synchro_private.h"
35
36 #include <signal.h>
37 #include "src/simix/ActorImpl.hpp"
38 #include "src/kernel/context/Context.hpp"
39
40 /********************************** Simix Global ******************************/
41
42 namespace simgrid {
43 namespace simix {
44
45 class Global {
46 public:
47   smx_context_factory_t context_factory = nullptr;
48   xbt_dynar_t process_to_run = nullptr;
49   xbt_dynar_t process_that_ran = nullptr;
50   xbt_swag_t process_list = nullptr;
51   xbt_swag_t process_to_destroy = nullptr;
52   smx_actor_t maestro_process = nullptr;
53
54   // Maps function names to actor code:
55   std::unordered_map<std::string, simgrid::simix::ActorCodeFactory> registered_functions;
56
57   // This might be used when no corresponding function name is registered:
58   simgrid::simix::ActorCodeFactory default_function;
59
60   smx_creation_func_t create_process_function = nullptr;
61   void_pfn_smxprocess_t kill_process_function = nullptr;
62   /** Callback used when killing a SMX_process */
63   void_pfn_smxprocess_t cleanup_process_function = nullptr;
64   xbt_os_mutex_t mutex = nullptr;
65
66   std::vector<simgrid::xbt::Task<void()>> tasks;
67   std::vector<simgrid::xbt::Task<void()>> tasksTemp;
68 };
69
70 }
71 }
72
73 SG_BEGIN_DECL()
74
75 XBT_PUBLIC_DATA(std::unique_ptr<simgrid::simix::Global>) simix_global;
76
77 XBT_PUBLIC(void) SIMIX_clean();
78
79 /******************************** Exceptions *********************************/
80 /** @brief Ask to the provided simix process to raise the provided exception */
81 #define SMX_EXCEPTION(issuer, cat, val, msg) \
82   if (1) { \
83   smx_actor_t _smx_throw_issuer = (issuer); /* evaluate only once */ \
84   xbt_ex e(XBT_THROW_POINT, msg); \
85   e.category = cat; \
86   e.value = val; \
87   _smx_throw_issuer->exception = std::make_exception_ptr(e); \
88   } else ((void)0)
89
90 /* ******************************** File ************************************ */
91 typedef struct s_smx_file {
92   surf_file_t surf_file;
93   void* data;                   /**< @brief user data */
94 } s_smx_file_t;
95
96
97 SG_END_DECL()
98
99 #endif