Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename smx_process_t to smx_actor_t
[simgrid.git] / src / kernel / context / ContextUnix.cpp
index 02b3a6e..550172e 100644 (file)
@@ -48,23 +48,23 @@ static void simgrid_makecontext(ucontext_t* ucp, void (*func)(int first, ...), v
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
 namespace simgrid {
-namespace simix {
+namespace kernel {
+namespace context {
   class UContext;
   class SerialUContext;
   class ParallelUContext;
   class UContextFactory;
-}
-}
+}}}
 
 #if HAVE_THREAD_CONTEXTS
 static xbt_parmap_t sysv_parmap;
-static simgrid::simix::ParallelUContext** sysv_workers_context;   /* space to save the worker's context in each thread */
+static simgrid::kernel::context::ParallelUContext** sysv_workers_context;   /* space to save the worker's context in each thread */
 static uintptr_t sysv_threads_working;     /* number of threads that have started their work */
 static xbt_os_thread_key_t sysv_worker_id_key; /* thread-specific storage for the thread id */
 #endif
 static unsigned long sysv_process_index = 0;   /* index of the next process to run in the
                                                 * list of runnable processes */
-static simgrid::simix::UContext* sysv_maestro_context;
+static simgrid::kernel::context::UContext* sysv_maestro_context;
 static bool sysv_parallel;
 
 // The name of this function is currently hardcoded in the code (as string).
@@ -72,7 +72,8 @@ static bool sysv_parallel;
 static void smx_ctx_sysv_wrapper(int first, ...);
 
 namespace simgrid {
-namespace simix {
+namespace kernel {
+namespace context {
 
 class UContext : public Context {
 protected:
@@ -81,14 +82,14 @@ protected:
 public:
   friend UContextFactory;
   UContext(std::function<void()>  code,
-    void_pfn_smxprocess_t cleanup_func, smx_process_t process);
+    void_pfn_smxprocess_t cleanup_func, smx_actor_t process);
   ~UContext() override;
 };
 
 class SerialUContext : public UContext {
 public:
   SerialUContext(std::function<void()>  code,
-      void_pfn_smxprocess_t cleanup_func, smx_process_t process)
+      void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
     : UContext(std::move(code), cleanup_func, process)
   {}
   void stop() override;
@@ -99,7 +100,7 @@ public:
 class ParallelUContext : public UContext {
 public:
   ParallelUContext(std::function<void()>  code,
-      void_pfn_smxprocess_t cleanup_func, smx_process_t process)
+      void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
     : UContext(std::move(code), cleanup_func, process)
   {}
   void stop() override;
@@ -116,7 +117,7 @@ public:
   UContextFactory();
   ~UContextFactory() override;
   Context* create_context(std::function<void()> code,
-    void_pfn_smxprocess_t cleanup, smx_process_t process) override;
+    void_pfn_smxprocess_t cleanup, smx_actor_t process) override;
   void run_all() override;
 };
 
@@ -175,7 +176,7 @@ void UContextFactory::run_all()
 
       xbt_parmap_apply(sysv_parmap,
         [](void* arg) {
-          smx_process_t process = (smx_process_t) arg;
+          smx_actor_t process = (smx_actor_t) arg;
           ParallelUContext* context = static_cast<ParallelUContext*>(process->context);
           context->resume();
         },
@@ -185,17 +186,20 @@ void UContextFactory::run_all()
     #endif
   } else {
     // Serial:
-      smx_process_t first_process =
-          xbt_dynar_get_as(simix_global->process_to_run, 0, smx_process_t);
-      sysv_process_index = 1;
-      SerialUContext* context =
+    if (xbt_dynar_is_empty(simix_global->process_to_run))
+      return;
+
+    smx_actor_t first_process =
+        xbt_dynar_get_as(simix_global->process_to_run, 0, smx_actor_t);
+    sysv_process_index = 1;
+    SerialUContext* context =
         static_cast<SerialUContext*>(first_process->context);
-      context->resume();
+    context->resume();
   }
 }
 
 Context* UContextFactory::create_context(std::function<void()> code,
-  void_pfn_smxprocess_t cleanup, smx_process_t process)
+  void_pfn_smxprocess_t cleanup, smx_actor_t process)
 {
   if (sysv_parallel)
     return new_context<ParallelUContext>(std::move(code), cleanup, process);
@@ -204,7 +208,7 @@ Context* UContextFactory::create_context(std::function<void()> code,
 }
 
 UContext::UContext(std::function<void()> code,
-    void_pfn_smxprocess_t cleanup_func, smx_process_t process)
+    void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
   : Context(std::move(code), cleanup_func, process)
 {
   /* if the user provided a function for the process then use it, otherwise it is the context for maestro */
@@ -233,14 +237,13 @@ UContext::~UContext()
   SIMIX_context_stack_delete(this->stack_);
 }
 
-}
-}
+}}} // namespace simgrid::kernel::context
 
 static void smx_ctx_sysv_wrapper(int first, ...)
 {
   // Rebuild the Context* pointer from the integers:
   int ctx_addr[CTX_ADDR_LEN];
-  simgrid::simix::UContext* context;
+  simgrid::kernel::context::UContext* context;
   ctx_addr[0] = first;
   if (CTX_ADDR_LEN > 1) {
     va_list ap;
@@ -249,14 +252,15 @@ static void smx_ctx_sysv_wrapper(int first, ...)
       ctx_addr[i] = va_arg(ap, int);
     va_end(ap);
   }
-  memcpy(&context, ctx_addr, sizeof(simgrid::simix::UContext*));
+  memcpy(&context, ctx_addr, sizeof(simgrid::kernel::context::UContext*));
 
   (*context)();
   context->stop();
 }
 
 namespace simgrid {
-namespace simix {
+namespace kernel {
+namespace context {
 
 void SerialUContext::stop()
 {
@@ -274,7 +278,7 @@ void SerialUContext::suspend()
     /* execute the next process */
     XBT_DEBUG("Run next process");
     next_context = (SerialUContext*) xbt_dynar_get_as(
-        simix_global->process_to_run,i, smx_process_t)->context;
+        simix_global->process_to_run,i, smx_actor_t)->context;
   }
   else {
     /* all processes were run, return to maestro */
@@ -346,7 +350,7 @@ void ParallelUContext::suspend()
 #if HAVE_THREAD_CONTEXTS
   /* determine the next context */
   // Get the next soul to embody now:
-  smx_process_t next_work = (smx_process_t) xbt_parmap_next(sysv_parmap);
+  smx_actor_t next_work = (smx_actor_t) xbt_parmap_next(sysv_parmap);
   ParallelUContext* next_context = nullptr;
   // Will contain the next soul to run, either simulated or initial minion's one
   ucontext_t* next_stack;
@@ -376,6 +380,5 @@ void ParallelUContext::suspend()
 #endif
 }
 
-}
-}
+}}} // namespace simgrid::kernel::context