/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+#include <functional>
+
#include "msg_private.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
+#include "xbt/functional.hpp"
#include "src/simix/smx_process_private.h"
#include "src/simix/smx_private.h"
simcall_process_set_data(smx_proc, NULL);
}
- TRACE_msg_process_destroy(smx_proc->name, smx_proc->pid);
+ TRACE_msg_process_destroy(smx_proc->name.c_str(), smx_proc->pid);
// free the data if a function was provided
if (msg_proc && msg_proc->data && msg_global->process_data_cleanup) {
msg_global->process_data_cleanup(msg_proc->data);
}
/* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
-smx_process_t MSG_process_create_from_SIMIX(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, smx_process_t parent_process)
+smx_process_t MSG_process_create_from_SIMIX(
+ const char *name, std::function<void()> code, void *data, const char *hostname,
+ double kill_time, xbt_dict_t properties,
+ int auto_restart, smx_process_t parent_process)
{
msg_host_t host = MSG_host_by_name(hostname);
- msg_process_t p = MSG_process_create_with_environment(name, code, data, host, argc, argv, properties);
+ msg_process_t p = MSG_process_create_with_environment(
+ name, std::move(code), data, host, properties);
if (p) {
MSG_process_set_kill_time(p,kill_time);
MSG_process_auto_restart_set(p,auto_restart);
* \return The new corresponding object.
*/
msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_func_t code, void *data, msg_host_t host,
- int argc, char **argv, xbt_dict_t properties)
+ int argc, char **argv, xbt_dict_t properties)
+{
+ msg_process_t res = MSG_process_create_with_environment(name,
+ code ? simgrid::xbt::wrapMain(code, argc, argv) : std::function<void()>(),
+ data, host,
+ properties);
+ for (int i = 0; i != argc; ++i)
+ xbt_free(argv[i]);
+ xbt_free(argv);
+ return res;
+}
+
+msg_process_t MSG_process_create_with_environment(
+ const char *name, std::function<void()> code, void *data,
+ msg_host_t host, xbt_dict_t properties)
{
xbt_assert(code != NULL && host != NULL, "Invalid parameters: host and code params must not be NULL");
simdata_process_t simdata = xbt_new0(s_simdata_process_t, 1);
simdata->waiting_action = NULL;
simdata->waiting_task = NULL;
simdata->m_host = host;
- simdata->argc = argc;
- simdata->argv = argv;
simdata->data = data;
simdata->last_errno = MSG_OK;
/* Let's create the process: SIMIX may decide to start it right now,
* even before returning the flow control to us */
- process = simcall_process_create(name, code, simdata, sg_host_get_name(host), -1, argc, argv, properties,0);
+ process = simcall_process_create(
+ name, std::move(code), simdata, sg_host_get_name(host), -1, properties, 0);
if (!process) {
/* Undo everything we have just changed */
simdata->waiting_action = NULL;
simdata->waiting_task = NULL;
simdata->m_host = host;
- simdata->argc = 0;
- simdata->argv = NULL;
simdata->data = data;
simdata->last_errno = MSG_OK;