Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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 blocked      = false;
58   bool suspended    = false;
59   bool auto_restart = false;
60
61   sg_host_t new_host            = nullptr;     /* if not null, the host on which the process must migrate to */
62   smx_synchro_t waiting_synchro = nullptr;  /* the current blocking synchro if any */
63   xbt_fifo_t comms              = nullptr;       /* the current non-blocking communication synchros */
64   xbt_dict_t properties         = nullptr;
65   s_smx_simcall_t simcall;
66   void *data          = nullptr;    /* kept for compatibility, it should be replaced with moddata */
67   xbt_dynar_t on_exit = nullptr; /* list of functions executed when the process dies */
68
69   std::function<void()> code;
70   smx_timer_t kill_timer = nullptr;
71   int segment_index      = 0;    /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
72
73   friend void intrusive_ptr_add_ref(Process* process)
74   {
75     auto previous = (process->refcount_)++;
76     xbt_assert(previous != 0);
77     (void) previous;
78   }
79   friend void intrusive_ptr_release(Process* process)
80   {
81     auto count = --(process->refcount_);
82     if (count == 0)
83       delete process;
84   }
85
86   ~Process();
87
88 private:
89   std::atomic_int_fast32_t refcount_ { 1 };
90 };
91
92 }
93 }
94
95 typedef simgrid::simix::ProcessArg *smx_process_arg_t;
96
97 typedef simgrid::simix::Process* smx_process_t;
98
99 SG_BEGIN_DECL()
100
101 XBT_PRIVATE smx_process_t SIMIX_process_create(
102                           const char *name,
103                           std::function<void()> code,
104                           void *data,
105                           const char *hostname,
106                           double kill_time,
107                           xbt_dict_t properties,
108                           int auto_restart,
109                           smx_process_t parent_process);
110
111 XBT_PRIVATE void SIMIX_process_runall(void);
112 XBT_PRIVATE void SIMIX_process_kill(smx_process_t process, smx_process_t issuer);
113 XBT_PRIVATE void SIMIX_process_killall(smx_process_t issuer, int reset_pid);
114 XBT_PRIVATE void SIMIX_process_stop(smx_process_t arg);
115 XBT_PRIVATE void SIMIX_process_cleanup(smx_process_t arg);
116 XBT_PRIVATE void SIMIX_process_empty_trash(void);
117 XBT_PRIVATE void SIMIX_process_yield(smx_process_t self);
118 XBT_PRIVATE void SIMIX_process_exception_terminate(xbt_ex_t * e);
119 XBT_PRIVATE void SIMIX_process_change_host(smx_process_t process,
120              sg_host_t dest);
121 XBT_PRIVATE smx_synchro_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer);
122 XBT_PRIVATE void SIMIX_process_resume(smx_process_t process, smx_process_t issuer);
123 XBT_PRIVATE int SIMIX_process_get_PID(smx_process_t self);
124 XBT_PRIVATE int SIMIX_process_get_PPID(smx_process_t self);
125 XBT_PRIVATE void* SIMIX_process_get_data(smx_process_t process);
126 XBT_PRIVATE void SIMIX_process_set_data(smx_process_t process, void *data);
127 XBT_PRIVATE sg_host_t SIMIX_process_get_host(smx_process_t process);
128 XBT_PRIVATE const char* SIMIX_process_get_name(smx_process_t process);
129 XBT_PRIVATE smx_process_t SIMIX_process_get_by_name(const char* name);
130 XBT_PRIVATE int SIMIX_process_is_suspended(smx_process_t process);
131 XBT_PRIVATE xbt_dict_t SIMIX_process_get_properties(smx_process_t process);
132 XBT_PRIVATE smx_synchro_t SIMIX_process_join(smx_process_t issuer, smx_process_t process, double timeout);
133 XBT_PRIVATE smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration);
134
135 XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_synchro_t synchro);
136 XBT_PRIVATE void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart);
137 XBT_PRIVATE smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer);
138
139 void SIMIX_segment_index_set(smx_process_t process, int segment_index);
140 extern void (*SMPI_switch_data_segment)(int dest);
141
142 SG_END_DECL()
143
144 #endif