1 /* Copyright (c) 2007-2010, 2012-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef _SIMIX_PRIVATE_H
8 #define _SIMIX_PRIVATE_H
12 #include <unordered_map>
15 #include <xbt/functional.hpp>
17 #include "src/internal_config.h"
18 #include "simgrid/simix.h"
19 #include "surf/surf.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"
37 #include "src/simix/ActorImpl.hpp"
41 #include <simgrid/simix.hpp>
46 /* This allows Java to hijack the context factory (Java induces factories of factory :) */
47 typedef ContextFactory* (*ContextFactoryInitializer)(void);
48 XBT_PUBLIC_DATA(ContextFactoryInitializer) factory_initializer;
50 XBT_PRIVATE ContextFactory* thread_factory();
51 XBT_PRIVATE ContextFactory* sysv_factory();
52 XBT_PRIVATE ContextFactory* raw_factory();
53 XBT_PRIVATE ContextFactory* boost_factory();
58 typedef simgrid::simix::ContextFactory *smx_context_factory_t;
62 typedef struct s_smx_context_factory *smx_context_factory_t;
66 /********************************** Simix Global ******************************/
73 smx_context_factory_t context_factory = nullptr;
74 xbt_dynar_t process_to_run = nullptr;
75 xbt_dynar_t process_that_ran = nullptr;
76 xbt_swag_t process_list = nullptr;
77 xbt_swag_t process_to_destroy = nullptr;
78 smx_process_t maestro_process = nullptr;
80 // Maps function names to actor code:
81 std::unordered_map<std::string, simgrid::simix::ActorCodeFactory> registered_functions;
83 // This might be used when no corresponding function name is registered:
84 simgrid::simix::ActorCodeFactory default_function;
86 smx_creation_func_t create_process_function = nullptr;
87 void_pfn_smxprocess_t kill_process_function = nullptr;
88 /** Callback used when killing a SMX_process */
89 void_pfn_smxprocess_t cleanup_process_function = nullptr;
90 xbt_os_mutex_t mutex = nullptr;
92 std::vector<simgrid::xbt::Task<void()>> tasks;
93 std::vector<simgrid::xbt::Task<void()>> tasksTemp;
101 XBT_PUBLIC_DATA(std::unique_ptr<simgrid::simix::Global>) simix_global;
103 extern XBT_PRIVATE unsigned long simix_process_maxpid;
105 XBT_PUBLIC(void) SIMIX_clean(void);
107 /******************************** Exceptions *********************************/
108 /** @brief Ask to the provided simix process to raise the provided exception */
109 #define SMX_EXCEPTION(issuer, cat, val, msg) \
111 smx_process_t _smx_throw_issuer = (issuer); /* evaluate only once */ \
112 xbt_ex e(XBT_THROW_POINT, msg); \
115 _smx_throw_issuer->exception = std::make_exception_ptr(e); \
118 /* ******************************** File ************************************ */
119 typedef struct s_smx_file {
120 surf_file_t surf_file;
121 void* data; /**< @brief user data */
124 XBT_PRIVATE void SIMIX_context_mod_init(void);
125 XBT_PRIVATE void SIMIX_context_mod_exit(void);
127 XBT_PRIVATE smx_context_t SIMIX_context_new(
128 std::function<void()> code,
129 void_pfn_smxprocess_t cleanup_func,
130 smx_process_t simix_process);
133 XBT_PUBLIC_DATA(char sigsegv_stack[SIGSTKSZ]);
136 /* We are using the bottom of the stack to save some information, like the
137 * valgrind_stack_id. Define smx_context_usable_stack_size to give the remaining
138 * size for the stack. */
140 # define smx_context_usable_stack_size \
141 (smx_context_stack_size - sizeof(unsigned int)) /* for valgrind_stack_id */
143 # define smx_context_usable_stack_size smx_context_stack_size
146 /** @brief Executes all the processes to run (in parallel if possible). */
147 static inline void SIMIX_context_runall(void)
149 if (!xbt_dynar_is_empty(simix_global->process_to_run))
150 simix_global->context_factory->run_all();
153 /** @brief returns the current running context */
154 static inline smx_context_t SIMIX_context_self(void)
156 if (simix_global && simix_global->context_factory)
157 return simix_global->context_factory->self();
162 XBT_PRIVATE void *SIMIX_context_stack_new(void);
163 XBT_PRIVATE void SIMIX_context_stack_delete(void *stack);
165 XBT_PRIVATE void SIMIX_context_set_current(smx_context_t context);
166 XBT_PRIVATE smx_context_t SIMIX_context_get_current(void);
168 XBT_PUBLIC(int) SIMIX_process_get_maxpid(void);
170 XBT_PRIVATE void SIMIX_post_create_environment(void);
172 // FIXME, Dirty hack for SMPI+MSG
173 XBT_PRIVATE void SIMIX_process_set_cleanup_function(smx_process_t process, void_pfn_smxprocess_t cleanup);
177 XBT_PRIVATE simgrid::simix::ActorCodeFactory& SIMIX_get_actor_code_factory(const char *name);