Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill useless field 'parallel_' in context factories.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 22 Dec 2019 22:45:08 +0000 (23:45 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 22 Dec 2019 23:15:29 +0000 (00:15 +0100)
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextSwapped.hpp
src/kernel/context/ContextThread.cpp
src/kernel/context/ContextThread.hpp

index 03a70bd..731a0f5 100644 (file)
@@ -38,7 +38,7 @@ namespace context {
 /* thread-specific storage for the worker's context */
 thread_local SwappedContext* SwappedContext::worker_context_ = nullptr;
 
-SwappedContextFactory::SwappedContextFactory() : ContextFactory(), parallel_(SIMIX_context_is_parallel())
+SwappedContextFactory::SwappedContextFactory() : ContextFactory()
 {
   parmap_ = nullptr; // will be created lazily with the right parameters if needed (ie, in parallel)
 }
@@ -47,7 +47,7 @@ SwappedContext::SwappedContext(std::function<void()>&& code, smx_actor_t actor,
     : Context(std::move(code), actor), factory_(factory)
 {
   // Save maestro (=context created first) in preparation for run_all
-  if (not factory->parallel_ && factory->maestro_context_ == nullptr)
+  if (not SIMIX_context_is_parallel() && factory->maestro_context_ == nullptr)
     factory->maestro_context_ = this;
 
   if (has_code()) {
@@ -154,7 +154,7 @@ void SwappedContextFactory::run_all()
    * stuff It is much easier to understand what happens if you see the working threads as bodies that swap their soul
    * for the ones of the simulated processes that must run.
    */
-  if (parallel_) {
+  if (SIMIX_context_is_parallel()) {
     // We lazily create the parmap so that all options are actually processed when doing so.
     if (parmap_ == nullptr)
       parmap_.reset(
@@ -192,7 +192,7 @@ void SwappedContextFactory::run_all()
  */
 void SwappedContext::resume()
 {
-  if (factory_->parallel_) {
+  if (SIMIX_context_is_parallel()) {
     // Save my current soul (either maestro, or one of the minions) in a thread-specific area
     worker_context_ = static_cast<SwappedContext*>(self());
     // Switch my soul and the actor's one
@@ -217,7 +217,7 @@ void SwappedContext::resume()
  */
 void SwappedContext::suspend()
 {
-  if (factory_->parallel_) {
+  if (SIMIX_context_is_parallel()) {
     // Get some more work to directly swap into the next executable actor instead of yielding back to the parmap
     boost::optional<smx_actor_t> next_work = factory_->parmap_->next();
     SwappedContext* next_context;
index 25f22c2..532287d 100644 (file)
@@ -24,8 +24,6 @@ public:
   void run_all() override;
 
 private:
-  bool parallel_;
-
   /* For the sequential execution */
   unsigned long process_index_     = 0;       // next actor to execute
   SwappedContext* maestro_context_ = nullptr; // save maestro's context
index 5f1f159..f7b3394 100644 (file)
@@ -22,21 +22,21 @@ namespace context {
 
 // ThreadContextFactory
 
-ThreadContextFactory::ThreadContextFactory() : ContextFactory(), parallel_(SIMIX_context_is_parallel())
+ThreadContextFactory::ThreadContextFactory() : ContextFactory()
 {
-  if (parallel_)
+  if (SIMIX_context_is_parallel())
     ParallelThreadContext::initialize();
 }
 
 ThreadContextFactory::~ThreadContextFactory()
 {
-  if (parallel_)
+  if (SIMIX_context_is_parallel())
     ParallelThreadContext::finalize();
 }
 
 ThreadContext* ThreadContextFactory::create_context(std::function<void()>&& code, actor::ActorImpl* actor, bool maestro)
 {
-  if (parallel_)
+  if (SIMIX_context_is_parallel())
     return this->new_context<ParallelThreadContext>(std::move(code), actor, maestro);
   else
     return this->new_context<SerialThreadContext>(std::move(code), actor, maestro);
@@ -44,7 +44,7 @@ ThreadContext* ThreadContextFactory::create_context(std::function<void()>&& code
 
 void ThreadContextFactory::run_all()
 {
-  if (parallel_) {
+  if (SIMIX_context_is_parallel()) {
     // Parallel execution
     ParallelThreadContext::run_all();
   } else {
index 259aef0..df885d6 100644 (file)
@@ -103,8 +103,6 @@ public:
   }
 
 private:
-  bool parallel_;
-
   ThreadContext* create_context(std::function<void()>&& code, actor::ActorImpl* actor, bool maestro);
 };
 } // namespace context