From b08cf565e62c980d3fa23c031b341ca4f1427bd9 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Thu, 19 May 2016 16:20:06 +0200 Subject: [PATCH] Make SIMIX_context_new() accept std::function --- src/simix/Context.cpp | 4 ++-- src/simix/smx_private.h | 4 +++- src/simix/smx_process.cpp | 6 ++++-- src/xbt/parmap.cpp | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/simix/Context.cpp b/src/simix/Context.cpp index a780e56745..d397833035 100644 --- a/src/simix/Context.cpp +++ b/src/simix/Context.cpp @@ -30,14 +30,14 @@ void SIMIX_process_set_cleanup_function( * \param cleanup_func the function to call when the context stops */ smx_context_t SIMIX_context_new( - xbt_main_func_t code, int argc, char **argv, + std::function code, void_pfn_smxprocess_t cleanup_func, smx_process_t simix_process) { if (!simix_global) xbt_die("simix is not initialized, please call MSG_init first"); return simix_global->context_factory->create_context( - simgrid::simix::wrap_main(code, argc, argv), cleanup_func, simix_process); + std::move(code), cleanup_func, simix_process); } namespace simgrid { diff --git a/src/simix/smx_private.h b/src/simix/smx_private.h index d0384513a9..02907e5213 100644 --- a/src/simix/smx_private.h +++ b/src/simix/smx_private.h @@ -7,6 +7,8 @@ #ifndef _SIMIX_PRIVATE_H #define _SIMIX_PRIVATE_H +#include + #include "src/internal_config.h" #include "simgrid/simix.h" #include "surf/surf.h" @@ -99,7 +101,7 @@ XBT_PRIVATE void SIMIX_context_mod_init(void); XBT_PRIVATE void SIMIX_context_mod_exit(void); XBT_PRIVATE smx_context_t SIMIX_context_new( - xbt_main_func_t code, int argc, char **argv, + std::function code, void_pfn_smxprocess_t cleanup_func, smx_process_t simix_process); diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 9c2273f863..08644bbc77 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -156,7 +156,7 @@ void create_maestro(std::function code) XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx); if (!code) { - maestro->context = SIMIX_context_new(NULL, 0, nullptr, NULL, maestro); + maestro->context = SIMIX_context_new(std::function(), NULL, maestro); } else { if (!simix_global) xbt_die("simix is not initialized, please call MSG_init first"); @@ -315,7 +315,9 @@ smx_process_t SIMIX_process_create( XBT_VERB("Create context %s", process->name); - process->context = SIMIX_context_new(code, argc, argv, simix_global->cleanup_process_function, process); + process->context = SIMIX_context_new( + simgrid::simix::wrap_main(code, argc, argv), + simix_global->cleanup_process_function, process); process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t)); XBT_RUNNING_CTX_INITIALIZE(process->running_ctx); diff --git a/src/xbt/parmap.cpp b/src/xbt/parmap.cpp index b4560478e1..2445b0b357 100644 --- a/src/xbt/parmap.cpp +++ b/src/xbt/parmap.cpp @@ -272,7 +272,7 @@ static void *xbt_parmap_worker_main(void *arg) xbt_parmap_thread_data_t data = (xbt_parmap_thread_data_t) arg; xbt_parmap_t parmap = data->parmap; unsigned round = 0; - smx_context_t context = SIMIX_context_new(NULL, 0, NULL, NULL, NULL); + smx_context_t context = SIMIX_context_new(std::function(), NULL, NULL); SIMIX_context_set_current(context); XBT_DEBUG("New worker thread created"); -- 2.20.1