Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
don't convert host to name to host. Perl epoch is over.
[simgrid.git] / src / simix / ActorImpl.hpp
1 /* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef _SIMIX_ACTORIMPL_H
7 #define _SIMIX_ACTORIMPL_H
8
9 #include <atomic>
10 #include <functional>
11 #include <string>
12
13 #include <xbt/base.h>
14 #include <xbt/string.hpp>
15
16 #include <simgrid/simix.hpp>
17 #include <simgrid/s4u/Actor.hpp>
18
19 #include "simgrid/simix.h"
20 #include "popping_private.h"
21
22 typedef struct s_smx_process_exit_fun {
23   int_f_pvoid_pvoid_t fun;
24   void *arg;
25 } s_smx_process_exit_fun_t, *smx_process_exit_fun_t;
26
27 namespace simgrid {
28 namespace simix {
29
30 class ProcessArg {
31 public:
32   std::string name;
33   std::function<void()> code;
34   void *data            = nullptr;
35   sg_host_t host        = nullptr;
36   double kill_time      = 0.0;
37   xbt_dict_t properties = nullptr;
38   bool auto_restart     = false;
39 };
40
41 class ActorImpl {
42 public:
43   ActorImpl() : piface_(this) {}
44
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 */
50
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 */
56
57   // TODO, pack them
58   std::exception_ptr exception;
59   bool finished     = false;
60   bool blocked      = false;
61   bool suspended    = false;
62   bool auto_restart = false;
63
64   sg_host_t new_host            = nullptr; /* if not null, the host on which the process must migrate to */
65   smx_activity_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 */
71
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*/
75
76   friend void intrusive_ptr_add_ref(ActorImpl* process)
77   {
78     // Atomic operation! Do not split in two instructions!
79     auto previous = (process->refcount_)++;
80     xbt_assert(previous != 0);
81     (void) previous;
82   }
83   friend void intrusive_ptr_release(ActorImpl* process)
84   {
85     // Atomic operation! Do not split in two instructions!
86     auto count = --(process->refcount_);
87     if (count == 0)
88       delete process;
89   }
90
91   ~ActorImpl();
92
93   simgrid::s4u::Actor& getIface() { return piface_; }
94
95 private:
96   std::atomic_int_fast32_t refcount_ { 1 };
97   simgrid::s4u::Actor piface_;
98 };
99
100 }
101 }
102
103 typedef simgrid::simix::ProcessArg *smx_process_arg_t;
104
105 typedef simgrid::simix::ActorImpl* smx_actor_t;
106
107 SG_BEGIN_DECL()
108
109 XBT_PRIVATE smx_actor_t SIMIX_process_create(
110                           const char *name,
111                           std::function<void()> code,
112                           void *data,
113                           sg_host_t host,
114                           double kill_time,
115                           xbt_dict_t properties,
116                           int auto_restart,
117                           smx_actor_t parent_process);
118
119 XBT_PRIVATE void SIMIX_process_runall();
120 XBT_PRIVATE void SIMIX_process_kill(smx_actor_t process, smx_actor_t issuer);
121 XBT_PRIVATE void SIMIX_process_killall(smx_actor_t issuer, int reset_pid);
122 XBT_PRIVATE void SIMIX_process_stop(smx_actor_t arg);
123 XBT_PRIVATE void SIMIX_process_cleanup(smx_actor_t arg);
124 XBT_PRIVATE void SIMIX_process_empty_trash();
125 XBT_PRIVATE void SIMIX_process_yield(smx_actor_t self);
126 XBT_PRIVATE void SIMIX_process_exception_terminate(xbt_ex_t * e);
127 XBT_PRIVATE void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest);
128 XBT_PRIVATE smx_activity_t SIMIX_process_suspend(smx_actor_t process, smx_actor_t issuer);
129 XBT_PRIVATE void SIMIX_process_resume(smx_actor_t process, smx_actor_t issuer);
130 XBT_PRIVATE int SIMIX_process_get_PID(smx_actor_t self);
131 XBT_PRIVATE void* SIMIX_process_get_data(smx_actor_t process);
132 XBT_PRIVATE void SIMIX_process_set_data(smx_actor_t process, void *data);
133 XBT_PRIVATE smx_actor_t SIMIX_process_get_by_name(const char* name);
134 XBT_PRIVATE int SIMIX_process_is_suspended(smx_actor_t process);
135 XBT_PRIVATE xbt_dict_t SIMIX_process_get_properties(smx_actor_t process);
136 XBT_PRIVATE smx_activity_t SIMIX_process_join(smx_actor_t issuer, smx_actor_t process, double timeout);
137 XBT_PRIVATE smx_activity_t SIMIX_process_sleep(smx_actor_t process, double duration);
138
139 XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_activity_t synchro);
140 XBT_PRIVATE void SIMIX_process_auto_restart_set(smx_actor_t process, int auto_restart);
141 XBT_PRIVATE smx_actor_t SIMIX_process_restart(smx_actor_t process, smx_actor_t issuer);
142
143 void SIMIX_segment_index_set(smx_actor_t process, int segment_index);
144 extern void (*SMPI_switch_data_segment)(int dest);
145
146 SG_END_DECL()
147
148 #endif