X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2be0e4648c5b7055580df1c265b7c43ee6763a46..36dffb4f8633c75ddaf66e398f432a8485e9e419:/src/msg/msg_process.c diff --git a/src/msg/msg_process.c b/src/msg/msg_process.c index 5030416b5e..d8fa002494 100644 --- a/src/msg/msg_process.c +++ b/src/msg/msg_process.c @@ -11,10 +11,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_process, msg, "Logging specific to MSG (process)"); -/** \defgroup m_process_management Management Functions of Agents - * \brief This section describes the agent structure of MSG - * (#m_process_t) and the functions for managing it. - */ /** @addtogroup m_process_management * \htmlonly \endhtmlonly * @@ -35,20 +31,27 @@ void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc) { simdata_process_t msg_proc; + // get the MSG process from the SIMIX process if (smx_proc == SIMIX_process_self()) { /* avoid a SIMIX request if this function is called by the process itself */ msg_proc = SIMIX_process_self_get_data(smx_proc); SIMIX_process_self_set_data(smx_proc, NULL); } else { - msg_proc = SIMIX_req_process_get_data(smx_proc); - SIMIX_req_process_set_data(smx_proc, NULL); + msg_proc = simcall_process_get_data(smx_proc); + simcall_process_set_data(smx_proc, NULL); } #ifdef HAVE_TRACING TRACE_msg_process_end(smx_proc); #endif + // free the data if a function was provided + if (msg_proc->data && msg_global->process_data_cleanup) { + msg_global->process_data_cleanup(msg_proc->data); + } + + // free the MSG process xbt_free(msg_proc); } @@ -171,7 +174,7 @@ m_process_t MSG_process_create_with_environment(const char *name, /* Let's create the process: SIMIX may decide to start it right now, * even before returning the flow control to us */ - SIMIX_req_process_create(&process, name, code, simdata, host->name, + simcall_process_create(&process, name, code, simdata, host->name, argc, argv, properties); if (!process) { @@ -204,12 +207,12 @@ void MSG_process_kill(m_process_t process) #endif /* FIXME: why do we only cancel communication actions? is this useful? */ - simdata_process_t p_simdata = SIMIX_req_process_get_data(process); + simdata_process_t p_simdata = simcall_process_get_data(process); if (p_simdata->waiting_task && p_simdata->waiting_task->simdata->comm) { - SIMIX_req_comm_cancel(p_simdata->waiting_task->simdata->comm); + simcall_comm_cancel(p_simdata->waiting_task->simdata->comm); } - SIMIX_req_process_kill(process); + simcall_process_kill(process); return; } @@ -222,13 +225,13 @@ void MSG_process_kill(m_process_t process) */ MSG_error_t MSG_process_migrate(m_process_t process, m_host_t host) { - simdata_process_t simdata = SIMIX_req_process_get_data(process); + simdata_process_t simdata = simcall_process_get_data(process); simdata->m_host = host; #ifdef HAVE_TRACING m_host_t now = simdata->m_host; TRACE_msg_process_change_host(process, now, host); #endif - SIMIX_req_process_change_host(process, host->simdata->smx_host); + simcall_process_change_host(process, host->simdata->smx_host); return MSG_OK; } @@ -243,7 +246,7 @@ void* MSG_process_get_data(m_process_t process) xbt_assert(process != NULL, "Invalid parameter"); /* get from SIMIX the MSG process data, and then the user data */ - simdata_process_t simdata = SIMIX_req_process_get_data(process); + simdata_process_t simdata = simcall_process_get_data(process); return simdata->data; } @@ -257,12 +260,23 @@ MSG_error_t MSG_process_set_data(m_process_t process, void *data) { xbt_assert(process != NULL, "Invalid parameter"); - simdata_process_t simdata = SIMIX_req_process_get_data(process); + simdata_process_t simdata = simcall_process_get_data(process); simdata->data = data; return MSG_OK; } +/** \ingroup m_process_management + * \brief Sets a cleanup function to be called to free the userdata of a + * process when a process is destroyed. + * \param data_cleanup a cleanup function for the userdata of a process, + * or NULL to call no function + */ +XBT_PUBLIC(void) MSG_process_set_data_cleanup(void_f_pvoid_t data_cleanup) { + + msg_global->process_data_cleanup = data_cleanup; +} + /** \ingroup m_process_management * \brief Return the location on which an agent is running. * \param process a process (NULL means the current one) @@ -276,7 +290,7 @@ m_host_t MSG_process_get_host(m_process_t process) simdata = SIMIX_process_self_get_data(SIMIX_process_self()); } else { - simdata = SIMIX_req_process_get_data(process); + simdata = simcall_process_get_data(process); } return simdata->m_host; } @@ -291,9 +305,12 @@ m_host_t MSG_process_get_host(m_process_t process) */ m_process_t MSG_process_from_PID(int PID) { - /* FIXME: reimplement this function using SIMIX when we have a good PID. - * In the meantime, I guess nobody uses it so it should not break anything. */ - THROW_UNIMPLEMENTED; + return SIMIX_process_from_PID(PID); +} + +/** @brief returns a list of all currently existing processes */ +xbt_dynar_t MSG_processes_as_dynar(void) { + return SIMIX_processes_as_dynar(); } /** \ingroup m_process_management @@ -310,7 +327,7 @@ int MSG_process_get_PID(m_process_t process) return 0; } - simdata_process_t simdata = SIMIX_req_process_get_data(process); + simdata_process_t simdata = simcall_process_get_data(process); return simdata != NULL ? simdata->PID : 0; } @@ -326,7 +343,7 @@ int MSG_process_get_PPID(m_process_t process) { xbt_assert(process != NULL, "Invalid parameter"); - simdata_process_t simdata = SIMIX_req_process_get_data(process); + simdata_process_t simdata = simcall_process_get_data(process); return simdata->PPID; } @@ -341,7 +358,7 @@ const char *MSG_process_get_name(m_process_t process) { xbt_assert(process, "Invalid parameter"); - return SIMIX_req_process_get_name(process); + return simcall_process_get_name(process); } /** \ingroup m_process_management @@ -366,7 +383,7 @@ xbt_dict_t MSG_process_get_properties(m_process_t process) { xbt_assert(process != NULL, "Invalid parameter"); - return SIMIX_req_process_get_properties(process); + return simcall_process_get_properties(process); } @@ -416,7 +433,7 @@ MSG_error_t MSG_process_suspend(m_process_t process) TRACE_msg_process_suspend(process); #endif - SIMIX_req_process_suspend(process); + simcall_process_suspend(process); MSG_RETURN(MSG_OK); } @@ -435,7 +452,7 @@ MSG_error_t MSG_process_resume(m_process_t process) TRACE_msg_process_resume(process); #endif - SIMIX_req_process_resume(process); + simcall_process_resume(process); MSG_RETURN(MSG_OK); } @@ -448,7 +465,7 @@ MSG_error_t MSG_process_resume(m_process_t process) int MSG_process_is_suspended(m_process_t process) { xbt_assert(process != NULL, "Invalid parameter"); - return SIMIX_req_process_is_suspended(process); + return simcall_process_is_suspended(process); } smx_context_t MSG_process_get_smx_ctx(m_process_t process) {