Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move a static field of SwappedContext into SwappedContextFactory
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 6 Jan 2019 11:06:03 +0000 (12:06 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 6 Jan 2019 11:06:03 +0000 (12:06 +0100)
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextSwapped.hpp

index 19f874d..4d277b7 100644 (file)
@@ -35,9 +35,6 @@ namespace simgrid {
 namespace kernel {
 namespace context {
 
 namespace kernel {
 namespace context {
 
-/* Sequential execution */
-unsigned long SwappedContext::process_index_;
-
 /* Parallel execution */
 simgrid::xbt::Parmap<smx_actor_t>* SwappedContext::parmap_;
 std::atomic<uintptr_t> SwappedContext::threads_working_;       /* number of threads that have started their work */
 /* Parallel execution */
 simgrid::xbt::Parmap<smx_actor_t>* SwappedContext::parmap_;
 std::atomic<uintptr_t> SwappedContext::threads_working_;       /* number of threads that have started their work */
@@ -84,10 +81,10 @@ void SwappedContextFactory::run_all()
   } else { // sequential execution
     if (simix_global->process_to_run.empty())
       return;
   } else { // sequential execution
     if (simix_global->process_to_run.empty())
       return;
-    smx_actor_t first_process      = simix_global->process_to_run.front();
-    SwappedContext::process_index_ = 1;
-    /* execute the first process */
-    static_cast<SwappedContext*>(first_process->context_)->resume();
+    smx_actor_t first_actor = simix_global->process_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();
   }
 }
 
   }
 }
 
@@ -213,8 +210,8 @@ void SwappedContext::suspend()
   } else { // sequential execution
     /* determine the next context */
     SwappedContext* next_context;
   } else { // sequential execution
     /* determine the next context */
     SwappedContext* next_context;
-    unsigned long int i = process_index_;
-    process_index_++;
+    unsigned long int i = factory_->process_index_;
+    factory_->process_index_++;
 
     if (i < simix_global->process_to_run.size()) {
       /* Actually swap into the next actor directly without transiting to maestro */
 
     if (i < simix_global->process_to_run.size()) {
       /* Actually swap into the next actor directly without transiting to maestro */
index 46c0b09..cfb9361 100644 (file)
@@ -22,8 +22,11 @@ public:
   ~SwappedContextFactory() override;
   void run_all() override;
 
   ~SwappedContextFactory() override;
   void run_all() override;
 
-protected: // FIXME temporary internal exposure
+protected:
   bool parallel_;
   bool parallel_;
+
+private:
+  unsigned long process_index_ = 0; // Next actor to execute during sequential run_all()
 };
 
 class SwappedContext : public Context {
 };
 
 class SwappedContext : public Context {
@@ -43,9 +46,7 @@ public:
   static SwappedContext* get_maestro() { return maestro_context_; }
   static void set_maestro(SwappedContext* maestro) { maestro_context_ = maestro; }
 
   static SwappedContext* get_maestro() { return maestro_context_; }
   static void set_maestro(SwappedContext* maestro) { maestro_context_ = maestro; }
 
-  static unsigned long process_index_; // FIXME killme
-
-  /* For the parallel execution */
+  /* For the parallel execution */ // FIXME killme
   static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
   static std::vector<SwappedContext*> workers_context_;
   static std::atomic<uintptr_t> threads_working_;
   static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
   static std::vector<SwappedContext*> workers_context_;
   static std::atomic<uintptr_t> threads_working_;