Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Register function names
[simgrid.git] / src / simix / smx_process_private.h
1 /* Copyright (c) 2007-2010, 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef _SIMIX_PROCESS_PRIVATE_H
8 #define _SIMIX_PROCESS_PRIVATE_H
9
10 #include <atomic>
11 #include <functional>
12 #include <string>
13
14 #include <xbt/base.h>
15 #include <xbt/string.hpp>
16
17 #include <simgrid/simix.hpp>
18 #include "simgrid/simix.h"
19 #include "popping_private.h"
20
21 typedef struct s_smx_process_exit_fun {
22   int_f_pvoid_pvoid_t fun;
23   void *arg;
24 } s_smx_process_exit_fun_t, *smx_process_exit_fun_t;
25
26 namespace simgrid {
27 namespace simix {
28
29 class ProcessArg {
30 public:
31   std::string name;
32   std::function<void()> code;
33   void *data            = nullptr;
34   const char *hostname  = nullptr;
35   double kill_time      = 0.0;
36   xbt_dict_t properties = nullptr;
37   bool auto_restart     = false;
38 };
39
40 class Process {
41 public:
42
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 */
48
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 */
54
55   // TODO, pack them
56   std::exception_ptr exception;
57   bool finished     = false;
58   bool blocked      = false;
59   bool suspended    = false;
60   bool auto_restart = false;
61
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 */
69
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*/
73
74   friend void intrusive_ptr_add_ref(Process* process)
75   {
76     // Atomic operation! Do not split in two instructions!
77     auto previous = (process->refcount_)++;
78     xbt_assert(previous != 0);
79     (void) previous;
80   }
81   friend void intrusive_ptr_release(Process* process)
82   {
83     // Atomic operation! Do not split in two instructions!
84     auto count = --(process->refcount_);
85     if (count == 0)
86       delete process;
87   }
88
89   ~Process();
90
91 private:
92   std::atomic_int_fast32_t refcount_ { 1 };
93 };
94
95 }
96 }
97
98 typedef simgrid::simix::ProcessArg *smx_process_arg_t;
99
100 typedef simgrid::simix::Process* smx_process_t;
101
102 SG_BEGIN_DECL()
103
104 XBT_PRIVATE smx_process_t SIMIX_process_create(
105                           const char *name,
106                           std::function<void()> code,
107                           void *data,
108                           const char *hostname,
109                           double kill_time,
110                           xbt_dict_t properties,
111                           int auto_restart,
112                           smx_process_t parent_process);
113
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,
123              sg_host_t dest);
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);
137
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);
141
142 void SIMIX_segment_index_set(smx_process_t process, int segment_index);
143 extern void (*SMPI_switch_data_segment)(int dest);
144
145 SG_END_DECL()
146
147 #endif