1 /* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef _SIMIX_ACTORIMPL_H
7 #define _SIMIX_ACTORIMPL_H
14 #include <xbt/string.hpp>
16 #include <simgrid/simix.hpp>
17 #include <simgrid/s4u/Actor.hpp>
19 #include "simgrid/simix.h"
20 #include "popping_private.h"
22 typedef struct s_smx_process_exit_fun {
23 int_f_pvoid_pvoid_t fun;
25 } s_smx_process_exit_fun_t, *smx_process_exit_fun_t;
33 std::function<void()> code;
35 const char *hostname = nullptr;
36 double kill_time = 0.0;
37 xbt_dict_t properties = nullptr;
38 bool auto_restart = false;
43 ActorImpl() : piface_(this) {}
45 // TODO, replace with boost intrusive container hooks
46 s_xbt_swag_hookup_t process_hookup = { nullptr, nullptr }; /* simix_global->process_list */
47 s_xbt_swag_hookup_t synchro_hookup = { nullptr, nullptr }; /* {mutex,cond,sem}->sleeping */
48 s_xbt_swag_hookup_t host_proc_hookup = { nullptr, nullptr }; /* smx_host->process_lis */
49 s_xbt_swag_hookup_t destroy_hookup = { nullptr, nullptr }; /* simix_global->process_to_destroy */
51 unsigned long pid = 0;
52 unsigned long ppid = 0;
53 simgrid::xbt::string name;
54 sg_host_t host = nullptr; /* the host on which the process is running */
55 smx_context_t context = nullptr; /* the context (uctx/raw/thread) that executes the user function */
58 std::exception_ptr exception;
59 bool finished = false;
61 bool suspended = false;
62 bool auto_restart = false;
64 sg_host_t new_host = nullptr; /* if not null, the host on which the process must migrate to */
65 smx_synchro_t waiting_synchro = nullptr; /* the current blocking synchro if any */
66 xbt_fifo_t comms = nullptr; /* the current non-blocking communication synchros */
67 xbt_dict_t properties = nullptr;
68 s_smx_simcall_t simcall;
69 void *data = nullptr; /* kept for compatibility, it should be replaced with moddata */
70 xbt_dynar_t on_exit = nullptr; /* list of functions executed when the process dies */
72 std::function<void()> code;
73 smx_timer_t kill_timer = nullptr;
74 int segment_index = 0; /* Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
76 friend void intrusive_ptr_add_ref(ActorImpl* process)
78 // Atomic operation! Do not split in two instructions!
79 auto previous = (process->refcount_)++;
80 xbt_assert(previous != 0);
83 friend void intrusive_ptr_release(ActorImpl* process)
85 // Atomic operation! Do not split in two instructions!
86 auto count = --(process->refcount_);
93 simgrid::s4u::Actor& getIface() { return piface_; }
96 std::atomic_int_fast32_t refcount_ { 1 };
97 simgrid::s4u::Actor piface_;
103 typedef simgrid::simix::ProcessArg *smx_process_arg_t;
105 typedef simgrid::simix::ActorImpl* smx_process_t;
109 XBT_PRIVATE smx_process_t SIMIX_process_create(
111 std::function<void()> code,
113 const char *hostname,
115 xbt_dict_t properties,
117 smx_process_t parent_process);
119 XBT_PRIVATE void SIMIX_process_runall();
120 XBT_PRIVATE void SIMIX_process_kill(smx_process_t process, smx_process_t issuer);
121 XBT_PRIVATE void SIMIX_process_killall(smx_process_t issuer, int reset_pid);
122 XBT_PRIVATE void SIMIX_process_stop(smx_process_t arg);
123 XBT_PRIVATE void SIMIX_process_cleanup(smx_process_t arg);
124 XBT_PRIVATE void SIMIX_process_empty_trash();
125 XBT_PRIVATE void SIMIX_process_yield(smx_process_t self);
126 XBT_PRIVATE void SIMIX_process_exception_terminate(xbt_ex_t * e);
127 XBT_PRIVATE void SIMIX_process_change_host(smx_process_t process, sg_host_t dest);
128 XBT_PRIVATE smx_synchro_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer);
129 XBT_PRIVATE void SIMIX_process_resume(smx_process_t process, smx_process_t issuer);
130 XBT_PRIVATE int SIMIX_process_get_PID(smx_process_t self);
131 XBT_PRIVATE void* SIMIX_process_get_data(smx_process_t process);
132 XBT_PRIVATE void SIMIX_process_set_data(smx_process_t process, void *data);
133 XBT_PRIVATE smx_process_t SIMIX_process_get_by_name(const char* name);
134 XBT_PRIVATE int SIMIX_process_is_suspended(smx_process_t process);
135 XBT_PRIVATE xbt_dict_t SIMIX_process_get_properties(smx_process_t process);
136 XBT_PRIVATE smx_synchro_t SIMIX_process_join(smx_process_t issuer, smx_process_t process, double timeout);
137 XBT_PRIVATE smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration);
139 XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_synchro_t synchro);
140 XBT_PRIVATE void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart);
141 XBT_PRIVATE smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer);
143 void SIMIX_segment_index_set(smx_process_t process, int segment_index);
144 extern void (*SMPI_switch_data_segment)(int dest);