X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ee6ffc12bf5523e4d2d2193138c791d991ec0ae4..2376a01092173679830310f4d57b267445959f97:/src/simix/Context.cpp diff --git a/src/simix/Context.cpp b/src/simix/Context.cpp index fbfffc9688..be5da21828 100644 --- a/src/simix/Context.cpp +++ b/src/simix/Context.cpp @@ -4,11 +4,18 @@ /* 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 + +#include +#include +#include + #include #include "mc/mc.h" #include +#include void SIMIX_process_set_cleanup_function( smx_process_t process, void_pfn_smxprocess_t cleanup) @@ -16,6 +23,25 @@ void SIMIX_process_set_cleanup_function( process->context->set_cleanup(cleanup); } +/** + * \brief creates a new context for a user level process + * \param code a main function + * \param argc the number of arguments of the main function + * \param argv the vector of arguments of the main function + * \param cleanup_func the function to call when the context stops + * \param cleanup_arg the argument of the cleanup_func function + */ +smx_context_t SIMIX_context_new( + xbt_main_func_t code, int argc, char **argv, + 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); +} + namespace simgrid { namespace simix { @@ -30,39 +56,40 @@ Context* ContextFactory::self() void ContextFactory::declare_context(void* context, std::size_t size) { -#ifdef HAVE_MC +#if HAVE_MC /* Store the address of the stack in heap to compare it apart of heap comparison */ if(MC_is_active()) MC_ignore_heap(context, size); #endif } -Context::Context(xbt_main_func_t code, - int argc, char **argv, - void_pfn_smxprocess_t cleanup_func, - smx_process_t process) - : process_(process), iwannadie(false) +Context* ContextFactory::attach(void_pfn_smxprocess_t cleanup_func, smx_process_t process) +{ + xbt_die("Cannot attach with this ContextFactory.\n" + "Try using --cfg=contexts/factory:thread instead.\n"); +} + +Context* ContextFactory::create_maestro(std::function code, smx_process_t process) +{ + xbt_die("Cannot create_maestro with this ContextFactory.\n" + "Try using --cfg=contexts/factory:thread instead.\n"); +} + +Context::Context(std::function code, + void_pfn_smxprocess_t cleanup_func, smx_process_t process) + : code_(std::move(code)), process_(process), iwannadie(false) { /* If the user provided a function for the process then use it. Otherwise, it is the context for maestro and we should set it as the current context */ - if (code) { + if (has_code()) this->cleanup_func_ = cleanup_func; - this->argc_ = argc; - this->argv_ = argv; - this->code_ = code; - } else { + else SIMIX_context_set_current(this); - } } Context::~Context() { - if (this->argv_) { - for (int i = 0; i < this->argc_; i++) - free(this->argv_[i]); - free(this->argv_); - } } void Context::stop() @@ -76,5 +103,9 @@ void Context::stop() this->iwannadie = true; } +AttachContext::~AttachContext() +{ +} + +} } -} \ No newline at end of file