X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ffe35f14793ff11fe9f1c4f7e78f6596ebfcc6e6..4606a1dce740efe467e6b9033b804294d376de8f:/src/simix/UContext.cpp diff --git a/src/simix/UContext.cpp b/src/simix/UContext.cpp index a5e8e8f564..af244c1872 100644 --- a/src/simix/UContext.cpp +++ b/src/simix/UContext.cpp @@ -8,6 +8,8 @@ #include +#include + #include "xbt/parmap.h" #include "smx_private.h" #include "smx_private.hpp" @@ -35,7 +37,7 @@ * variable is decomposed into a serie of integers and * each integer is passed as argument to makecontext. */ XBT_PRIVATE -void simgrid_makecontext(ucontext* ucp, void (*func)(int first, ...), void* arg) +void simgrid_makecontext(ucontext_t* ucp, void (*func)(int first, ...), void* arg) { int ctx_addr[CTX_ADDR_LEN]; memcpy(ctx_addr, &arg, sizeof(void*)); @@ -83,10 +85,8 @@ protected: char *stack_ = nullptr; /* the thread stack */ public: friend UContextFactory; - UContext(xbt_main_func_t code, - int argc, char **argv, - void_pfn_smxprocess_t cleanup_func, - smx_process_t process); + UContext(std::function code, + void_pfn_smxprocess_t cleanup_func, smx_process_t process); ~UContext(); protected: static void wrapper(int first, ...); @@ -94,11 +94,9 @@ protected: class SerialUContext : public UContext { public: - SerialUContext(xbt_main_func_t code, - int argc, char **argv, - void_pfn_smxprocess_t cleanup_func, - smx_process_t process) - : UContext(code, argc, argv, cleanup_func, process) + SerialUContext(std::function code, + void_pfn_smxprocess_t cleanup_func, smx_process_t process) + : UContext(std::move(code), cleanup_func, process) {} void stop() override; void suspend() override; @@ -107,11 +105,9 @@ public: class ParallelUContext : public UContext { public: - ParallelUContext(xbt_main_func_t code, - int argc, char **argv, - void_pfn_smxprocess_t cleanup_func, - smx_process_t process) - : UContext(code, argc, argv, cleanup_func, process) + ParallelUContext(std::function code, + void_pfn_smxprocess_t cleanup_func, smx_process_t process) + : UContext(std::move(code), cleanup_func, process) {} void stop() override; void suspend() override; @@ -126,10 +122,8 @@ public: UContextFactory(); virtual ~UContextFactory(); - virtual Context* create_context( - xbt_main_func_t, int, char **, void_pfn_smxprocess_t, - smx_process_t process - ) override; + virtual Context* create_context(std::function code, + void_pfn_smxprocess_t, smx_process_t process) override; void run_all() override; }; @@ -207,27 +201,22 @@ void UContextFactory::run_all() } } -Context* UContextFactory::create_context( - xbt_main_func_t code, int argc, char ** argv, - void_pfn_smxprocess_t cleanup, - smx_process_t process - ) +Context* UContextFactory::create_context(std::function code, + void_pfn_smxprocess_t cleanup, smx_process_t process) { if (sysv_parallel) - return new_context(code, argc, argv, cleanup, process); + return new_context(std::move(code), cleanup, process); else - return new_context(code, argc, argv, cleanup, process); + return new_context(std::move(code), cleanup, process); } -UContext::UContext(xbt_main_func_t code, - int argc, char **argv, - void_pfn_smxprocess_t cleanup_func, - smx_process_t process) - : Context(code, argc, argv, cleanup_func, process) +UContext::UContext(std::function code, + void_pfn_smxprocess_t cleanup_func, smx_process_t process) + : Context(std::move(code), cleanup_func, process) { /* if the user provided a function for the process then use it, otherwise it is the context for maestro */ - if (code) { + if (has_code()) { this->stack_ = (char*) SIMIX_context_stack_new(); getcontext(&this->uc_); this->uc_.uc_link = nullptr; @@ -243,7 +232,7 @@ UContext::UContext(xbt_main_func_t code, #ifdef HAVE_MC if (MC_is_active() && code) { - MC_register_stack_area(this->stack_, context->process, + MC_register_stack_area(this->stack_, process, &(this->uc_), smx_context_usable_stack_size); } #endif