X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/891abf1a3579d0e378a6e1b3426e5c34b23a58ad..467a0c53018ee489de1dd7ae61a083d52048b8e8:/src/simix/smx_process.cpp diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 836d2d0ae8..d7654ef19a 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -6,6 +6,8 @@ #include +#include + #include "src/surf/surf_interface.hpp" #include "smx_private.h" #include "xbt/sysdep.h" @@ -28,6 +30,21 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX unsigned long simix_process_maxpid = 0; +/** Increase the refcount for this process */ +smx_process_t SIMIX_process_ref(smx_process_t process) +{ + if (process != nullptr) + intrusive_ptr_add_ref(process); + return process; +} + +/** Decrease the refcount for this process */ +void SIMIX_process_unref(smx_process_t process) +{ + if (process != nullptr) + intrusive_ptr_release(process); +} + /** * \brief Returns the current agent. * @@ -136,9 +153,12 @@ namespace simix { Process::~Process() { delete this->context; - xbt_dict_free(&this->properties); - xbt_fifo_free(this->comms); - xbt_dynar_free(&this->on_exit); + if (this->properties) + xbt_dict_free(&this->properties); + if (this->comms != nullptr) + xbt_fifo_free(this->comms); + if (this->on_exit) + xbt_dynar_free(&this->on_exit); } void create_maestro(std::function code) @@ -975,6 +995,44 @@ void SIMIX_segment_index_set(smx_process_t proc, int index){ proc->segment_index = index; } +/** + * \ingroup simix_process_management + * \brief Creates and runs a new SIMIX process. + * + * The structure and the corresponding thread are created and put in the list of ready processes. + * + * \param name a name for the process. It is for user-level information and can be nullptr. + * \param code the main function of the process + * \param data a pointer to any data one may want to attach to the new object. It is for user-level information and can be nullptr. + * It can be retrieved with the function \ref simcall_process_get_data. + * \param hostname name of the host where the new agent is executed. + * \param kill_time time when the process is killed + * \param argc first argument passed to \a code + * \param argv second argument passed to \a code + * \param properties the properties of the process + * \param auto_restart either it is autorestarting or not. + */ +smx_process_t simcall_process_create(const char *name, + xbt_main_func_t code, + void *data, + const char *hostname, + double kill_time, + int argc, char **argv, + xbt_dict_t properties, + int auto_restart) +{ + if (name == nullptr) + name = ""; + auto wrapped_code = simgrid::xbt::wrapMain(code, argc, argv); + for (int i = 0; i != argc; ++i) + xbt_free(argv[i]); + xbt_free(argv); + smx_process_t res = simcall_process_create(name, + std::move(wrapped_code), + data, hostname, kill_time, properties, auto_restart); + return res; +} + smx_process_t simcall_process_create( const char *name, std::function code, void *data, const char *hostname, double kill_time, @@ -989,4 +1047,4 @@ smx_process_t simcall_process_create( kill_time, properties, auto_restart, self); }); -} \ No newline at end of file +}