Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Noreturn annotations in contexts.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 9 Jan 2020 10:41:07 +0000 (11:41 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 9 Jan 2020 11:09:37 +0000 (12:09 +0100)
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextBoost.hpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextRaw.hpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextSwapped.hpp
src/kernel/context/ContextThread.hpp
src/kernel/context/ContextUnix.cpp

index 71274db..27f801f 100644 (file)
@@ -64,6 +64,7 @@ void BoostContext::wrapper(BoostContext::arg_type arg)
   }
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
+  THROW_IMPOSSIBLE;
 }
 
 void BoostContext::swap_into(SwappedContext* to_)
index 687a3c1..6445635 100644 (file)
@@ -45,7 +45,7 @@ private:
   typedef boost::context::detail::transfer_t arg_type;
 #endif
 
-  static void wrapper(arg_type arg);
+  XBT_ATTRIB_NORETURN static void wrapper(arg_type arg);
 };
 
 class BoostContextFactory : public SwappedContextFactory {
index 721508c..1d39323 100644 (file)
@@ -220,6 +220,7 @@ void RawContext::wrapper(RawContext* context)
   }
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
+  THROW_IMPOSSIBLE;
 }
 
 void RawContext::swap_into(SwappedContext* to_)
index a016e98..2d975e7 100644 (file)
@@ -34,7 +34,7 @@ private:
   /** pointer to top the stack stack */
   void* stack_top_ = nullptr;
 
-  static void wrapper(RawContext* context);
+  XBT_ATTRIB_NORETURN static void wrapper(RawContext* context);
 };
 
 class RawContextFactory : public SwappedContextFactory {
index 3bea171..292cb59 100644 (file)
@@ -187,35 +187,32 @@ void SwappedContextFactory::run_all()
  */
 void SwappedContext::resume()
 {
+  SwappedContext* old = static_cast<SwappedContext*>(self());
   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
-    Context::set_current(this);
-    worker_context_->swap_into(this);
-    // No body runs that soul anymore at this point, but it is stored in a safe place.
-    // When the executed actor will do a blocking action, ActorImpl::yield() will call suspend(), below.
-  } else { // sequential execution
-    SwappedContext* old = static_cast<SwappedContext*>(self());
-    Context::set_current(this);
-    old->swap_into(this);
+    worker_context_ = old;
   }
+  // Switch my soul and the actor's one
+  Context::set_current(this);
+  old->swap_into(this);
+  // No body runs that soul anymore at this point, but it is stored in a safe place.
+  // When the executed actor will do a blocking action, ActorImpl::yield() will call suspend(), below.
 }
 
 /** The actor wants to yield back to maestro, because it is blocked in a simcall (i.e., in ActorImpl::yield())
  *
  * Actually, it does not really yield back to maestro, but directly into the next executable actor.
  *
- * This makes the parmap::apply awkward (see ParallelUContext::run_all()) because it only apply regularly
+ * This makes the parmap::apply awkward (see SwappedContextFactory::run_all()) because it only apply regularly
  * on the few first elements of the array, but it saves a lot of context switches back to maestro,
  * and directly forth to the next executable actor.
  */
 void SwappedContext::suspend()
 {
+  SwappedContext* next_context;
   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;
     if (next_work) {
       // There is a next soul to embody (ie, another executable actor)
       XBT_DEBUG("Run next process");
@@ -227,14 +224,8 @@ void SwappedContext::suspend()
       next_context = worker_context_;
       // When given that soul, the body will wait for the next scheduling round
     }
-
-    // Get the next soul to run, either from another actor or the initial minion's one
-    Context::set_current(next_context);
-    this->swap_into(next_context);
-
   } else { // sequential execution
     /* determine the next context */
-    SwappedContext* next_context;
     unsigned long int i = factory_->process_index_;
     factory_->process_index_++;
 
@@ -247,9 +238,9 @@ void SwappedContext::suspend()
       XBT_DEBUG("No more actors to run");
       next_context = factory_->maestro_context_;
     }
-    Context::set_current(next_context);
-    this->swap_into(next_context);
   }
+  Context::set_current(next_context);
+  this->swap_into(next_context);
 }
 
 } // namespace context
index 5e526ce..4c03501 100644 (file)
@@ -41,7 +41,7 @@ public:
 
   void suspend() override;
   virtual void resume();
-  void stop() override;
+  XBT_ATTRIB_NORETURN void stop() override;
 
   virtual void swap_into(SwappedContext* to) = 0; // Defined in Raw, Boost and UContext subclasses
 
index 8974140..a5e74f5 100644 (file)
@@ -24,7 +24,7 @@ public:
   ThreadContext(const ThreadContext&) = delete;
   ThreadContext& operator=(const ThreadContext&) = delete;
   ~ThreadContext() override;
-  void stop() override;
+  XBT_ATTRIB_NORETURN void stop() override;
   void suspend() override;
   void attach_start() override;
   void attach_stop() override;
index ced08e1..c074806 100644 (file)
@@ -25,7 +25,7 @@ static_assert(sizeof(simgrid::kernel::context::UContext*) <= CTX_ADDR_LEN * size
 
 /* Make sure that this symbol is easy to recognize by name, even on exotic platforms */
 extern "C" {
-static void smx_ctx_wrapper(int i1, int i2);
+XBT_ATTRIB_NORETURN static void smx_ctx_wrapper(int i1, int i2);
 }
 
 // The name of this function is currently hardcoded in MC (as string).
@@ -49,6 +49,7 @@ static void smx_ctx_wrapper(int i1, int i2)
   }
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
+  THROW_IMPOSSIBLE;
 }
 
 namespace simgrid {