* is assumed to be the maestro. */
XBT_PUBLIC void SIMIX_set_maestro(void (*code)(void*), void* data);
-XBT_PUBLIC void SIMIX_function_register_process_cleanup(void_pfn_smxprocess_t function);
-XBT_PUBLIC void SIMIX_function_register_process_kill(void_pfn_smxprocess_t function);
-
/* Simulation execution */
XBT_PUBLIC void SIMIX_run();
XBT_PUBLIC double SIMIX_get_clock();
/* props */ std::unordered_map<std::string, std::string>*,
/* parent_process */ smx_actor_t);
-XBT_PUBLIC void SIMIX_function_register_process_create(smx_creation_func_t function);
-
XBT_PUBLIC smx_actor_t simcall_process_create(std::string name, simgrid::simix::ActorCode code, void* data,
sg_host_t host, std::unordered_map<std::string, std::string>* properties);
SIMIX_process_kill(this, (this == simix_global->maestro_process) ? this : SIMIX_process_self());
// start the new process
- ActorImpl* actor = simix_global->create_process_function(arg.name.c_str(), std::move(arg.code), arg.data, arg.host,
- arg.properties.get(), nullptr);
+ ActorImpl* actor =
+ SIMIX_process_create(arg.name.c_str(), std::move(arg.code), arg.data, arg.host, arg.properties.get(), nullptr);
simcall_process_set_kill_time(actor, arg.kill_time);
actor->set_auto_restart(arg.auto_restart);
process->code = code;
XBT_VERB("Create context %s", process->get_cname());
- process->context_ = SIMIX_context_new(std::move(code), simix_global->cleanup_process_function, process);
+ process->context_ = SIMIX_context_new(std::move(code), &SIMIX_process_cleanup, process);
/* Add properties */
if (properties != nullptr)
XBT_VERB("Create context %s", process->get_cname());
if (not simix_global)
xbt_die("simix is not initialized, please call MSG_init first");
- process->context_ = simix_global->context_factory->attach(simix_global->cleanup_process_function, process);
+ process->context_ = simix_global->context_factory->attach(&SIMIX_process_cleanup, process);
/* Add properties */
if (properties != nullptr)
xbt_die("Not a suitable context");
auto process = context->process();
- simix_global->cleanup_process_function(process);
+ SIMIX_process_cleanup(process);
context->attach_stop();
}
void simcall_process_set_kill_time(smx_actor_t process, double kill_time)
{
- if (kill_time <= SIMIX_get_clock() || simix_global->kill_process_function == nullptr)
+ if (kill_time <= SIMIX_get_clock())
return;
XBT_DEBUG("Set kill time %f for process %s@%s", kill_time, process->get_cname(), process->host_->get_cname());
process->kill_timer = SIMIX_timer_set(kill_time, [process] {
- simix_global->kill_process_function(process);
+ SIMIX_process_kill(process, nullptr);
process->kill_timer=nullptr;
});
}
if (not simix_global) {
simix_global = std::unique_ptr<simgrid::simix::Global>(new simgrid::simix::Global());
simix_global->maestro_process = nullptr;
- simix_global->create_process_function = &SIMIX_process_create;
- simix_global->kill_process_function = &kill_process;
- simix_global->cleanup_process_function = &SIMIX_process_cleanup;
surf_init(argc, argv); /* Initialize SURF structures */
SIMIX_context_mod_init();
return timer ? timer->getDate() : 0;
}
-/**
- * @brief Registers a function to create a process.
- *
- * This function registers a function to be called
- * when a new process is created. The function has
- * to call SIMIX_process_create().
- * @param function create process function
- */
-void SIMIX_function_register_process_create(smx_creation_func_t function)
-{
- simix_global->create_process_function = function;
-}
-
-/**
- * @brief Registers a function to kill a process.
- *
- * This function registers a function to be called when a process is killed. The function has to call the
- * SIMIX_process_kill().
- *
- * @param function Kill process function
- */
-void SIMIX_function_register_process_kill(void_pfn_smxprocess_t function)
-{
- simix_global->kill_process_function = function;
-}
-
-/**
- * @brief Registers a function to cleanup a process.
- *
- * This function registers a user function to be called when a process ends properly.
- *
- * @param function cleanup process function
- */
-void SIMIX_function_register_process_cleanup(void_pfn_smxprocess_t function)
-{
- simix_global->cleanup_process_function = function;
-}
-
-
void SIMIX_display_process_status()
{
int nbprocess = simix_global->process_list.size();
// This might be used when no corresponding function name is registered:
simgrid::simix::ActorCodeFactory default_function;
- smx_creation_func_t create_process_function = nullptr;
- void_pfn_smxprocess_t kill_process_function = nullptr;
- /** Callback used when killing a SMX_process */
- void_pfn_smxprocess_t cleanup_process_function = nullptr;
std::mutex mutex;
std::vector<simgrid::xbt::Task<void()>> tasks;
{
for (auto const& arg : actors_at_boot_) {
XBT_DEBUG("Booting Actor %s(%s) right now", arg->name.c_str(), arg->host->get_cname());
- smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host,
- arg->properties.get(), nullptr);
+ smx_actor_t actor =
+ SIMIX_process_create(arg->name.c_str(), arg->code, nullptr, arg->host, arg->properties.get(), nullptr);
if (arg->kill_time >= 0)
simcall_process_set_kill_time(actor, arg->kill_time);
if (arg->auto_restart)
XBT_DEBUG("Process %s@%s will be started at time %f", arg->name.c_str(), arg->host->get_cname(), start_time);
SIMIX_timer_set(start_time, [arg, auto_restart]() {
- smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), std::move(arg->code), arg->data,
- arg->host, arg->properties.get(), nullptr);
+ smx_actor_t actor = SIMIX_process_create(arg->name.c_str(), std::move(arg->code), arg->data, arg->host,
+ arg->properties.get(), nullptr);
if (arg->kill_time >= 0)
simcall_process_set_kill_time(actor, arg->kill_time);
if (auto_restart)
} else { // start_time <= SIMIX_get_clock()
XBT_DEBUG("Starting Process %s(%s) right now", arg->name.c_str(), host->get_cname());
- smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), std::move(code), nullptr, host,
- arg->properties.get(), nullptr);
+ smx_actor_t actor =
+ SIMIX_process_create(arg->name.c_str(), std::move(code), nullptr, host, arg->properties.get(), nullptr);
/* The actor creation will fail if the host is currently dead, but that's fine */
if (actor != nullptr) {