From 78f2b1a0a46589cd083afd39fb84a90c4c043288 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Wed, 18 May 2016 17:08:06 +0200 Subject: [PATCH 1/1] Make s_smx_process_t a C++ class (constructor, new, delete) --- include/simgrid/msg.h | 2 +- include/simgrid/simix.h | 19 ++++++--- src/simix/smx_global.cpp | 3 +- src/simix/smx_host.cpp | 2 +- src/simix/smx_process.cpp | 8 ++-- src/simix/smx_process_private.h | 75 +++++++++++++++++++-------------- src/simix/smx_synchro.cpp | 6 +-- 7 files changed, 65 insertions(+), 50 deletions(-) diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index cf5119057b..f13dbce103 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -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 diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 59b4c3da9a..8f31a42b4b 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -21,16 +21,28 @@ namespace simgrid { namespace simix { + + /** @brief Process datatype + @ingroup simix_process_management + + A process may be defined as a code, with some private + data, executing in a location. + \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 code, with some private - data, executing in a location. - \see m_process_management - @{ */ -typedef struct s_smx_process *smx_process_t; typedef enum { SMX_EXIT_SUCCESS = 0, SMX_EXIT_FAILURE = 1 diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 8489bf628c..dbfb7f9bbd 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -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)); diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index bfc4f205db..985bdcd404 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -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 */ diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 87d4355103..9c2273f863 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -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 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); diff --git a/src/simix/smx_process_private.h b/src/simix/smx_process_private.h index 89a28c3dc0..bf93b7fe76 100644 --- a/src/simix/smx_process_private.h +++ b/src/simix/smx_process_private.h @@ -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, diff --git a/src/simix/smx_synchro.cpp b/src/simix/smx_synchro.cpp index f5c9244aab..e82964e853 100644 --- a/src/simix/smx_synchro.cpp +++ b/src/simix/smx_synchro.cpp @@ -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)); -- 2.20.1