- msg_proc = (simdata_process_t) simcall_process_get_data(smx_proc);
- simcall_process_set_data(smx_proc, NULL);
+ msg_actor = (MsgActorExt*)smx_actor->data;
+ simcall_process_set_data(smx_actor, nullptr);
- if (msg_proc && msg_proc->data && msg_global->process_data_cleanup) {
- msg_global->process_data_cleanup(msg_proc->data);
+ if (msg_actor && msg_actor->data && msg_global->process_data_cleanup) {
+ msg_global->process_data_cleanup(msg_actor->data);
-smx_process_t MSG_process_create_from_SIMIX(const char *name, xbt_main_func_t code, void *data, const char *hostname,
- double kill_time, simgrid::simix::args args, xbt_dict_t properties,
- int auto_restart, smx_process_t parent_process)
+smx_actor_t MSG_process_create_from_SIMIX(
+ const char *name, std::function<void()> code, void *data, sg_host_t host,
+ double kill_time, xbt_dict_t properties,
+ int auto_restart, smx_actor_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, args.argc(), args.to_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);
if (p) {
MSG_process_set_kill_time(p,kill_time);
MSG_process_auto_restart_set(p,auto_restart);
*/
msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *data, msg_host_t host)
{
*/
msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *data, msg_host_t host)
{
- return MSG_process_create_with_environment(name, code, data, host, 0, NULL, NULL);
+ return MSG_process_create_with_environment(name, code, data, host, 0, nullptr, nullptr);
* A constructor for #msg_process_t taking four arguments and returning the corresponding object. The structure (and
* the corresponding thread) is created, and put in the list of ready process.
* A constructor for #msg_process_t taking four arguments and returning the corresponding object. The structure (and
* the corresponding thread) is created, and put in the list of ready process.
* \param code is a function describing the behavior of the process. It should then only use functions described
* in \ref m_process_management (to create a new #msg_process_t for example),
in \ref m_host_management (only the read-only functions i.e. whose name contains the word get),
in \ref m_task_management (to create or destroy some #msg_task_t for example) and
in \ref msg_task_usage (to handle file transfers and task processing).
* \param data a pointer to any data one may want to attach to the new object. It is for user-level information and
* \param code is a function describing the behavior of the process. It should then only use functions described
* in \ref m_process_management (to create a new #msg_process_t for example),
in \ref m_host_management (only the read-only functions i.e. whose name contains the word get),
in \ref m_task_management (to create or destroy some #msg_task_t for example) and
in \ref msg_task_usage (to handle file transfers and task processing).
* \param data a pointer to any data one may want to attach to the new object. It is for user-level information and
* \param host the location where the new process is executed.
* \param argc first argument passed to \a code
* \param argv second argument passed to \a code
* \param host the location where the new process is executed.
* \param argc first argument passed to \a code
* \param argv second argument passed to \a code
msg_process_t MSG_process_create_with_arguments(const char *name, xbt_main_func_t code, void *data, msg_host_t host,
int argc, char **argv)
{
msg_process_t MSG_process_create_with_arguments(const char *name, xbt_main_func_t code, void *data, msg_host_t host,
int argc, char **argv)
{
- return MSG_process_create_with_environment(name, code, data, host, argc, argv, NULL);
+ return MSG_process_create_with_environment(name, code, data, host, argc, argv, nullptr);
* A constructor for #msg_process_t taking four arguments and returning the corresponding object. The structure (and
* the corresponding thread) is created, and put in the list of ready process.
* A constructor for #msg_process_t taking four arguments and returning the corresponding object. The structure (and
* the corresponding thread) is created, and put in the list of ready process.
* \param code is a function describing the behavior of the process. It should then only use functions described
* in \ref m_process_management (to create a new #msg_process_t for example),
in \ref m_host_management (only the read-only functions i.e. whose name contains the word get),
in \ref m_task_management (to create or destroy some #msg_task_t for example) and
in \ref msg_task_usage (to handle file transfers and task processing).
* \param data a pointer to any data one may want to attach to the new object. It is for user-level information and
* \param code is a function describing the behavior of the process. It should then only use functions described
* in \ref m_process_management (to create a new #msg_process_t for example),
in \ref m_host_management (only the read-only functions i.e. whose name contains the word get),
in \ref m_task_management (to create or destroy some #msg_task_t for example) and
in \ref msg_task_usage (to handle file transfers and task processing).
* \param data a pointer to any data one may want to attach to the new object. It is for user-level information and
* \param host the location where the new process is executed.
* \param argc first argument passed to \a code
* \param argv second argument passed to \a code. WARNING, these strings are freed by the SimGrid kernel when the
* \param host the location where the new process is executed.
* \param argc first argument passed to \a code
* \param argv second argument passed to \a code. WARNING, these strings are freed by the SimGrid kernel when the
* \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,
* \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,
- 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);
- msg_process_t process;
+ std::function<void()> function;
+ if (code)
+ function = simgrid::xbt::wrapMain(code, argc, const_cast<const char*const*>(argv));
+ msg_process_t res = MSG_process_create_with_environment(name,
+ std::move(function), data, host, properties);
+ for (int i = 0; i != argc; ++i)
+ xbt_free(argv[i]);
+ xbt_free(argv);
+ return res;
+}
- /* Simulator data for MSG */
- simdata->waiting_action = NULL;
- simdata->waiting_task = NULL;
- simdata->m_host = host;
- simdata->data = data;
- simdata->last_errno = MSG_OK;
+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 != nullptr && host != nullptr, "Invalid parameters: host and code params must not be nullptr");
+ MsgActorExt* msgExt = new MsgActorExt(data);
/* Let's create the process: SIMIX may decide to start it right now,
* even before returning the flow control to us */
/* 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);
+ msg_process_t process = simcall_process_create(name, std::move(code), msgExt, host, -1, properties, 0);
/* Become a process in the simulation
*
* Currently this can only be called by the main thread (once) and only work with some thread factories
/* Become a process in the simulation
*
* Currently this can only be called by the main thread (once) and only work with some thread factories
*/
msg_process_t MSG_process_attach(const char *name, void *data, msg_host_t host, xbt_dict_t properties)
{
*/
msg_process_t MSG_process_attach(const char *name, void *data, msg_host_t host, xbt_dict_t properties)
{
- xbt_assert(host != NULL, "Invalid parameters: host and code params must not be NULL");
- simdata_process_t simdata = xbt_new0(s_simdata_process_t, 1);
- msg_process_t process;
-
- /* Simulator data for MSG */
- simdata->waiting_action = NULL;
- simdata->waiting_task = NULL;
- simdata->m_host = host;
- simdata->data = data;
- simdata->last_errno = MSG_OK;
+ xbt_assert(host != nullptr, "Invalid parameters: host and code params must not be nullptr");
- process = SIMIX_process_attach(name, simdata, sg_host_get_name(host), properties, NULL);
+ msg_process_t process = SIMIX_process_attach(name, new MsgActorExt(data), host->cname(), properties, nullptr);
if (!process)
xbt_die("Could not attach");
simcall_process_on_exit(process,(int_f_pvoid_pvoid_t)TRACE_msg_process_kill,process);
if (!process)
xbt_die("Could not attach");
simcall_process_on_exit(process,(int_f_pvoid_pvoid_t)TRACE_msg_process_kill,process);
* Used in the main thread, it waits for the simulation to finish before returning. When it returns, the other
* simulated processes and the maestro are destroyed.
*/
* Used in the main thread, it waits for the simulation to finish before returning. When it returns, the other
* simulated processes and the maestro are destroyed.
*/
-// /* FIXME: why do we only cancel communication actions? is this useful? */
-// simdata_process_t p_simdata = simcall_process_get_data(process);
-// if (p_simdata->waiting_task && p_simdata->waiting_task->simdata->comm) {
-// simcall_comm_cancel(p_simdata->waiting_task->simdata->comm);
-// }
- simdata_process_t simdata = (simdata_process_t) simcall_process_get_data(process);
- simdata->m_host = host;
- msg_host_t now = simdata->m_host;
- TRACE_msg_process_change_host(process, now, host);
+ TRACE_msg_process_change_host(process, MSG_process_get_host(process), host);
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.
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.
*/
XBT_PUBLIC(void) MSG_process_set_data_cleanup(void_f_pvoid_t data_cleanup) {
msg_global->process_data_cleanup = data_cleanup;
*/
XBT_PUBLIC(void) MSG_process_set_data_cleanup(void_f_pvoid_t data_cleanup) {
msg_global->process_data_cleanup = data_cleanup;
* \return the msg_host_t corresponding to the location on which \a process is running.
*/
msg_host_t MSG_process_get_host(msg_process_t process)
{
* \return the msg_host_t corresponding to the location on which \a process is running.
*/
msg_host_t MSG_process_get_host(msg_process_t process)
{
- simdata_process_t simdata;
- if (process == NULL) {
- simdata = (simdata_process_t) SIMIX_process_self_get_data();
- }
- else {
- simdata = (simdata_process_t) simcall_process_get_data(process);
+ if (process == nullptr) {
+ return MSG_process_self()->host;
+ } else {
+ return process->host;
* \brief Return a #msg_process_t given its PID.
*
* This function search in the list of all the created msg_process_t for a msg_process_t whose PID is equal to \a PID.
* \brief Return a #msg_process_t given its PID.
*
* This function search in the list of all the created msg_process_t for a msg_process_t whose PID is equal to \a PID.
Note that the PID are uniq in the whole simulation, not only on a given host.
*/
msg_process_t MSG_process_from_PID(int PID)
Note that the PID are uniq in the whole simulation, not only on a given host.
*/
msg_process_t MSG_process_from_PID(int PID)
{
/* Do not raise an exception here: this function is called by the logs
* and the exceptions, so it would be called back again and again */
{
/* Do not raise an exception here: this function is called by the logs
* and the exceptions, so it would be called back again and again */