Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv ActorImpl where it belongs
[simgrid.git] / src / kernel / context / ContextSwapped.cpp
index 9aabd63..8226815 100644 (file)
@@ -6,8 +6,8 @@
 #include "simgrid/Exception.hpp"
 #include "simgrid/modelchecker.h"
 #include "src/internal_config.h"
+#include "src/kernel/actor/ActorImpl.hpp"
 #include "src/kernel/context/context_private.hpp"
-#include "src/simix/ActorImpl.hpp"
 #include "src/simix/smx_private.hpp"
 #include "xbt/parmap.hpp"
 
@@ -43,12 +43,8 @@ SwappedContextFactory::SwappedContextFactory() : ContextFactory(), parallel_(SIM
   parmap_ = nullptr; // will be created lazily with the right parameters if needed (ie, in parallel)
   workers_context_.resize(parallel_ ? SIMIX_context_get_nthreads() : 1, nullptr);
 }
-SwappedContextFactory::~SwappedContextFactory()
-{
-  delete parmap_;
-}
 
-SwappedContext::SwappedContext(std::function<void()> code, smx_actor_t actor, SwappedContextFactory* factory)
+SwappedContext::SwappedContext(std::function<void()>&& code, smx_actor_t actor, SwappedContextFactory* factory)
     : Context(std::move(code), actor), factory_(factory)
 {
   // Save maestro (=context created first) in preparation for run_all
@@ -164,7 +160,8 @@ void SwappedContextFactory::run_all()
 
     // We lazily create the parmap so that all options are actually processed when doing so.
     if (parmap_ == nullptr)
-      parmap_ = new simgrid::xbt::Parmap<smx_actor_t>(SIMIX_context_get_nthreads(), SIMIX_context_get_parallel_mode());
+      parmap_.reset(
+          new simgrid::xbt::Parmap<smx_actor_t>(SIMIX_context_get_nthreads(), SIMIX_context_get_parallel_mode()));
 
     // Usually, Parmap::apply() executes the provided function on all elements of the array.
     // Here, the executed function does not return the control to the parmap before all the array is processed:
@@ -174,7 +171,7 @@ void SwappedContextFactory::run_all()
     //   - So, resume() is only launched from the parmap for the first job of each minion.
     parmap_->apply(
         [](smx_actor_t process) {
-          SwappedContext* context = static_cast<SwappedContext*>(process->context_);
+          SwappedContext* context = static_cast<SwappedContext*>(process->context_.get());
           context->resume();
         },
         simix_global->actors_to_run);
@@ -186,7 +183,7 @@ void SwappedContextFactory::run_all()
     smx_actor_t first_actor = simix_global->actors_to_run.front();
     process_index_          = 1;
     /* execute the first actor; it will chain to the others when using suspend() */
-    static_cast<SwappedContext*>(first_actor->context_)->resume();
+    static_cast<SwappedContext*>(first_actor->context_.get())->resume();
   }
 }
 
@@ -233,7 +230,7 @@ void SwappedContext::suspend()
     if (next_work) {
       // There is a next soul to embody (ie, another executable actor)
       XBT_DEBUG("Run next process");
-      next_context = static_cast<SwappedContext*>(next_work.get()->context_);
+      next_context = static_cast<SwappedContext*>(next_work.get()->context_.get());
     } else {
       // All actors were run, go back to the parmap context
       XBT_DEBUG("No more actors to run");
@@ -255,7 +252,7 @@ void SwappedContext::suspend()
     if (i < simix_global->actors_to_run.size()) {
       /* Actually swap into the next actor directly without transiting to maestro */
       XBT_DEBUG("Run next actor");
-      next_context = static_cast<SwappedContext*>(simix_global->actors_to_run[i]->context_);
+      next_context = static_cast<SwappedContext*>(simix_global->actors_to_run[i]->context_.get());
     } else {
       /* all processes were run, actually return to maestro */
       XBT_DEBUG("No more actors to run");