Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make s_smx_process_t a C++ class (constructor, new, delete)
authorGabriel Corona <gabriel.corona@loria.fr>
Wed, 18 May 2016 15:08:06 +0000 (17:08 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 23 May 2016 07:05:21 +0000 (09:05 +0200)
include/simgrid/msg.h
include/simgrid/simix.h
src/simix/smx_global.cpp
src/simix/smx_host.cpp
src/simix/smx_process.cpp
src/simix/smx_process_private.h
src/simix/smx_synchro.cpp

index cf51190..f13dbce 100644 (file)
@@ -152,7 +152,7 @@ typedef struct msg_comm *msg_comm_t;
     structure, but always use the provided API to interact with
     processes.
  */
-typedef struct s_smx_process *msg_process_t;
+typedef smx_process_t msg_process_t;
 
 /** @brief Return code of most MSG functions
     @ingroup msg_simulation
index 59b4c3d..8f31a42 100644 (file)
 
 namespace simgrid {
 namespace simix {
+
+  /** @brief Process datatype
+      @ingroup simix_process_management
+
+      A process may be defined as a <em>code</em>, with some <em>private
+      data</em>, executing in a <em>location</em>.
+      \see m_process_management
+    @{ */
+  class Process;
   class Context;
   class ContextFactory;
+
 }
 }
 
 typedef simgrid::simix::Context *smx_context_t;
+typedef simgrid::simix::Process *smx_process_t;
 
 #else
 
 typedef struct s_smx_context *smx_context_t;
+typedef struct s_smx_process *smx_process_t;
 
 #endif
 
@@ -92,14 +104,7 @@ typedef xbt_dictelm_t smx_storage_t;
 typedef struct s_smx_storage_priv *smx_storage_priv_t;
 
 /* ****************************** Process *********************************** */
-/** @brief Process datatype
-    @ingroup simix_process_management
 
-    A process may be defined as a <em>code</em>, with some <em>private
-    data</em>, executing in a <em>location</em>.
-    \see m_process_management
-  @{ */
-typedef struct s_smx_process *smx_process_t;
 typedef enum {
   SMX_EXIT_SUCCESS = 0,
   SMX_EXIT_FAILURE = 1
index 8489bf6..dbfb7f9 100644 (file)
@@ -188,11 +188,10 @@ void SIMIX_global_init(int *argc, char **argv)
   simgrid::mc::Client::initialize();
 #endif
 
-  s_smx_process_t proc;
-
   if (!simix_global) {
     simix_global = xbt_new0(s_smx_global_t, 1);
 
+    simgrid::simix::Process proc;
     simix_global->process_to_run = xbt_dynar_new(sizeof(smx_process_t), NULL);
     simix_global->process_that_ran = xbt_dynar_new(sizeof(smx_process_t), NULL);
     simix_global->process_list = xbt_swag_new(xbt_swag_offset(proc, process_hookup));
index bfc4f20..985bdcd 100644 (file)
@@ -23,9 +23,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts");
 void SIMIX_host_create(sg_host_t host) // FIXME: braindead prototype. Take sg_host as parameter
 {
   smx_host_priv_t smx_host = xbt_new0(s_smx_host_priv_t, 1);
-  s_smx_process_t proc;
 
   /* Host structure */
+  simgrid::simix::Process proc;
   smx_host->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
 
   /* Update global variables */
index 87d4355..9c2273f 100644 (file)
@@ -136,7 +136,7 @@ void SIMIX_process_empty_trash(void)
     xbt_dynar_free(&process->on_exit);
 
     xbt_free(process->name);
-    xbt_free(process);
+    delete process;
   }
 }
 
@@ -147,7 +147,7 @@ void create_maestro(std::function<void()> code)
 {
   smx_process_t maestro = NULL;
   /* Create maestro process and intilialize it */
-  maestro = xbt_new0(s_smx_process_t, 1);
+  maestro = new simgrid::simix::Process();
   maestro->pid = simix_process_maxpid++;
   maestro->ppid = -1;
   maestro->name = (char*) "";
@@ -277,7 +277,7 @@ smx_process_t SIMIX_process_create(
     xbt_free(argv);
   }
   else {
-    process = xbt_new0(s_smx_process_t, 1);
+    process = new simgrid::simix::Process();
 
     xbt_assert(((code != NULL) && (host != NULL)), "Invalid parameters");
     /* Process data */
@@ -368,7 +368,7 @@ smx_process_t SIMIX_process_attach(
     return nullptr;
   }
 
-  smx_process_t process = xbt_new0(s_smx_process_t, 1);
+  smx_process_t process = new simgrid::simix::Process();
   /* Process data */
   process->pid = simix_process_maxpid++;
   process->name = xbt_strdup(name);
index 89a28c3..bf93b7f 100644 (file)
@@ -12,8 +12,6 @@
 #include "simgrid/simix.h"
 #include "popping_private.h"
 
-SG_BEGIN_DECL()
-
 typedef struct s_smx_process_exit_fun {
   int_f_pvoid_pvoid_t fun;
   void *arg;
@@ -31,39 +29,52 @@ typedef struct s_smx_process_arg {
   unsigned auto_restart:1;
 } s_smx_process_arg_t, *smx_process_arg_t;
 
-/** @brief Process datatype */
-typedef struct s_smx_process {
-  s_xbt_swag_hookup_t process_hookup;   /* simix_global->process_list */
-  s_xbt_swag_hookup_t synchro_hookup;   /* {mutex,cond,sem}->sleeping */
-  s_xbt_swag_hookup_t host_proc_hookup; /* smx_host->process_lis */
-  s_xbt_swag_hookup_t destroy_hookup;   /* simix_global->process_to_destroy */
-
-  unsigned long pid;
-  unsigned long ppid;
-  char *name;                   /**< @brief process name if any */
-  sg_host_t host;          /* the host on which the process is running */
-  smx_context_t context;        /* the context (uctx/raw/thread) that executes the user function */
-  xbt_running_ctx_t *running_ctx;
-  unsigned doexception:1;
-  unsigned blocked:1;
-  unsigned suspended:1;
-  unsigned auto_restart:1;
-
-  sg_host_t new_host;          /* if not null, the host on which the process must migrate to */
-  smx_synchro_t waiting_synchro;  /* the current blocking synchro if any */
-  xbt_fifo_t comms;       /* the current non-blocking communication synchros */
-  xbt_dict_t properties;
+namespace simgrid {
+namespace simix {
+
+class Process {
+public:
+
+  // TODO, replace with boost intrusive container hooks
+  s_xbt_swag_hookup_t process_hookup = { nullptr, nullptr };   /* simix_global->process_list */
+  s_xbt_swag_hookup_t synchro_hookup = { nullptr, nullptr };   /* {mutex,cond,sem}->sleeping */
+  s_xbt_swag_hookup_t host_proc_hookup = { nullptr, nullptr }; /* smx_host->process_lis */
+  s_xbt_swag_hookup_t destroy_hookup = { nullptr, nullptr };   /* simix_global->process_to_destroy */
+
+  unsigned long pid = 0;
+  unsigned long ppid = 0;
+  char *name = nullptr;         /**< @brief process name if any */
+  sg_host_t host = nullptr;     /* the host on which the process is running */
+  smx_context_t context = nullptr; /* the context (uctx/raw/thread) that executes the user function */
+  xbt_running_ctx_t *running_ctx = nullptr;
+
+  // TODO, pack them
+  bool doexception = false;
+  bool blocked = false;
+  bool suspended = false;
+  bool auto_restart = false;
+
+  sg_host_t new_host = nullptr;     /* if not null, the host on which the process must migrate to */
+  smx_synchro_t waiting_synchro = nullptr;  /* the current blocking synchro if any */
+  xbt_fifo_t comms = nullptr;       /* the current non-blocking communication synchros */
+  xbt_dict_t properties = nullptr;
   s_smx_simcall_t simcall;
-  void *data;                   /* kept for compatibility, it should be replaced with moddata */
-  xbt_dynar_t on_exit;     /* list of functions executed when the process dies */
+  void *data = nullptr;    /* kept for compatibility, it should be replaced with moddata */
+  xbt_dynar_t on_exit = nullptr; /* list of functions executed when the process dies */
 
-  xbt_main_func_t code;
-  int argc;
-  char **argv;
-  smx_timer_t kill_timer;
-  int segment_index;    /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
-} s_smx_process_t;
+  xbt_main_func_t code = nullptr;
+  int argc = 0;
+  char **argv = nullptr;
+  smx_timer_t kill_timer = nullptr;
+  int segment_index = 0;    /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
+};
+
+}
+}
 
+typedef simgrid::simix::Process* smx_process_t;
+
+SG_BEGIN_DECL()
 
 XBT_PRIVATE smx_process_t SIMIX_process_create(
                           const char *name,
index f5c9244..e82964e 100644 (file)
@@ -105,7 +105,7 @@ smx_mutex_t simcall_HANDLER_mutex_init(smx_simcall_t simcall){
 smx_mutex_t SIMIX_mutex_init(void)
 {
   XBT_IN("()");
-  s_smx_process_t p;            /* useful to initialize sleeping swag */
+  simgrid::simix::Process p;            /* useful to initialize sleeping swag */
 
   smx_mutex_t mutex = xbt_new0(s_smx_mutex_t, 1);
   mutex->locked = 0;
@@ -231,7 +231,7 @@ void SIMIX_mutex_destroy(smx_mutex_t mutex)
 smx_cond_t SIMIX_cond_init(void)
 {
   XBT_IN("()");
-  s_smx_process_t p;
+  simgrid::simix::Process p;
   smx_cond_t cond = xbt_new0(s_smx_cond_t, 1);
   cond->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup));
   cond->mutex = NULL;
@@ -372,7 +372,7 @@ void SIMIX_cond_destroy(smx_cond_t cond)
 smx_sem_t SIMIX_sem_init(unsigned int value)
 {
   XBT_IN("(%u)",value);
-  s_smx_process_t p;
+  simgrid::simix::Process p;
 
   smx_sem_t sem = xbt_new0(s_smx_sem_t, 1);
   sem->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup));