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_PROCESS_PRIVATE_H
8 #define _SIMIX_PROCESS_PRIVATE_H
15 #include <xbt/string.hpp>
17 #include <simgrid/simix.hpp>
18 #include <simgrid/s4u/actor.hpp>
20 #include "simgrid/simix.h"
21 #include "popping_private.h"
23 typedef struct s_smx_process_exit_fun {
24 int_f_pvoid_pvoid_t fun;
26 } s_smx_process_exit_fun_t, *smx_process_exit_fun_t;
34 std::function<void()> code;
36 const char *hostname = nullptr;
37 double kill_time = 0.0;
38 xbt_dict_t properties = nullptr;
39 bool auto_restart = false;
44 Process() : actor_(this) {}
46 // TODO, replace with boost intrusive container hooks
47 s_xbt_swag_hookup_t process_hookup = { nullptr, nullptr }; /* simix_global->process_list */
48 s_xbt_swag_hookup_t synchro_hookup = { nullptr, nullptr }; /* {mutex,cond,sem}->sleeping */
49 s_xbt_swag_hookup_t host_proc_hookup = { nullptr, nullptr }; /* smx_host->process_lis */
50 s_xbt_swag_hookup_t destroy_hookup = { nullptr, nullptr }; /* simix_global->process_to_destroy */
52 unsigned long pid = 0;
53 unsigned long ppid = 0;
54 simgrid::xbt::string name;
55 sg_host_t host = nullptr; /* the host on which the process is running */
56 smx_context_t context = nullptr; /* the context (uctx/raw/thread) that executes the user function */
59 std::exception_ptr exception;
60 bool finished = false;
62 bool suspended = false;
63 bool auto_restart = false;
65 sg_host_t new_host = nullptr; /* if not null, the host on which the process must migrate to */
66 smx_synchro_t waiting_synchro = nullptr; /* the current blocking synchro if any */
67 xbt_fifo_t comms = nullptr; /* the current non-blocking communication synchros */
68 xbt_dict_t properties = nullptr;
69 s_smx_simcall_t simcall;
70 void *data = nullptr; /* kept for compatibility, it should be replaced with moddata */
71 xbt_dynar_t on_exit = nullptr; /* list of functions executed when the process dies */
73 std::function<void()> code;
74 smx_timer_t kill_timer = nullptr;
75 int segment_index = 0; /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
77 friend void intrusive_ptr_add_ref(Process* process)
79 // Atomic operation! Do not split in two instructions!
80 auto previous = (process->refcount_)++;
81 xbt_assert(previous != 0);
84 friend void intrusive_ptr_release(Process* process)
86 // Atomic operation! Do not split in two instructions!
87 auto count = --(process->refcount_);
94 simgrid::s4u::Actor& actor() { return actor_; }
97 std::atomic_int_fast32_t refcount_ { 1 };
98 simgrid::s4u::Actor actor_;
104 typedef simgrid::simix::ProcessArg *smx_process_arg_t;
106 typedef simgrid::simix::Process* smx_process_t;
110 XBT_PRIVATE smx_process_t SIMIX_process_create(
112 std::function<void()> code,
114 const char *hostname,
116 xbt_dict_t properties,
118 smx_process_t parent_process);
120 XBT_PRIVATE void SIMIX_process_runall(void);
121 XBT_PRIVATE void SIMIX_process_kill(smx_process_t process, smx_process_t issuer);
122 XBT_PRIVATE void SIMIX_process_killall(smx_process_t issuer, int reset_pid);
123 XBT_PRIVATE void SIMIX_process_stop(smx_process_t arg);
124 XBT_PRIVATE void SIMIX_process_cleanup(smx_process_t arg);
125 XBT_PRIVATE void SIMIX_process_empty_trash(void);
126 XBT_PRIVATE void SIMIX_process_yield(smx_process_t self);
127 XBT_PRIVATE void SIMIX_process_exception_terminate(xbt_ex_t * e);
128 XBT_PRIVATE void SIMIX_process_change_host(smx_process_t process,
130 XBT_PRIVATE smx_synchro_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer);
131 XBT_PRIVATE void SIMIX_process_resume(smx_process_t process, smx_process_t issuer);
132 XBT_PRIVATE int SIMIX_process_get_PID(smx_process_t self);
133 XBT_PRIVATE int SIMIX_process_get_PPID(smx_process_t self);
134 XBT_PRIVATE void* SIMIX_process_get_data(smx_process_t process);
135 XBT_PRIVATE void SIMIX_process_set_data(smx_process_t process, void *data);
136 XBT_PRIVATE sg_host_t SIMIX_process_get_host(smx_process_t process);
137 XBT_PRIVATE const char* SIMIX_process_get_name(smx_process_t process);
138 XBT_PRIVATE smx_process_t SIMIX_process_get_by_name(const char* name);
139 XBT_PRIVATE int SIMIX_process_is_suspended(smx_process_t process);
140 XBT_PRIVATE xbt_dict_t SIMIX_process_get_properties(smx_process_t process);
141 XBT_PRIVATE smx_synchro_t SIMIX_process_join(smx_process_t issuer, smx_process_t process, double timeout);
142 XBT_PRIVATE smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration);
144 XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_synchro_t synchro);
145 XBT_PRIVATE void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart);
146 XBT_PRIVATE smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer);
148 void SIMIX_segment_index_set(smx_process_t process, int segment_index);
149 extern void (*SMPI_switch_data_segment)(int dest);