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