X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/87c589b94e563580e8e0585079cdba97914d791d..15f9e0adbd11d2a0736440004a2f71ef9cfccab8:/src/kernel/context/ContextBoost.cpp diff --git a/src/kernel/context/ContextBoost.cpp b/src/kernel/context/ContextBoost.cpp index b2e23315d8..37a348195f 100644 --- a/src/kernel/context/ContextBoost.cpp +++ b/src/kernel/context/ContextBoost.cpp @@ -15,41 +15,19 @@ namespace kernel { namespace context { // BoostContextFactory - -BoostContextFactory::BoostContextFactory() - : ContextFactory("BoostContextFactory"), parallel_(SIMIX_context_is_parallel()) -{ - BoostContext::set_maestro(nullptr); - if (parallel_) - ParallelBoostContext::initialize(); -} - -BoostContextFactory::~BoostContextFactory() -{ - if (parallel_) - ParallelBoostContext::finalize(); -} - smx_context_t BoostContextFactory::create_context(std::function code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process) { if (parallel_) - return this->new_context(std::move(code), cleanup_func, process); - return this->new_context(std::move(code), cleanup_func, process); -} - -void BoostContextFactory::run_all() -{ - if (parallel_) - ParallelBoostContext::run_all(); - else - SwappedContext::run_all(); + return this->new_context(std::move(code), cleanup_func, process, this); + return this->new_context(std::move(code), cleanup_func, process, this); } // BoostContext -BoostContext::BoostContext(std::function code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process) - : SwappedContext(std::move(code), cleanup_func, process) +BoostContext::BoostContext(std::function code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process, + SwappedContextFactory* factory) + : SwappedContext(std::move(code), cleanup_func, process, factory) { /* if the user provided a function for the process then use it, otherwise it is the context for maestro */ @@ -128,27 +106,7 @@ void BoostContext::swap_into(SwappedContext* to_) #endif } -void BoostContext::stop() -{ - Context::stop(); - throw StopRequest(); -} - // ParallelBoostContext - -void ParallelBoostContext::run_all() -{ - threads_working_ = 0; - if (parmap_ == nullptr) - parmap_ = new simgrid::xbt::Parmap(SIMIX_context_get_nthreads(), SIMIX_context_get_parallel_mode()); - parmap_->apply( - [](smx_actor_t process) { - ParallelBoostContext* context = static_cast(process->context_); - context->resume(); - }, - simix_global->process_to_run); -} - void ParallelBoostContext::suspend() { boost::optional next_work = parmap_->next(); @@ -169,8 +127,8 @@ void ParallelBoostContext::resume() { worker_id_ = threads_working_.fetch_add(1, std::memory_order_relaxed); - ParallelBoostContext* worker_context = static_cast(self()); - workers_context_[worker_id_] = worker_context; + SwappedContext* worker_context = static_cast(self()); + workers_context_[worker_id_] = worker_context; Context::set_current(this); worker_context->swap_into(this);