From: Arnaud Giersch Date: Thu, 9 Jan 2020 10:41:07 +0000 (+0100) Subject: Noreturn annotations in contexts. X-Git-Tag: v3.25~127 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a76526cb68465af7b566a4afc6fff7893be6a94d Noreturn annotations in contexts. --- diff --git a/src/kernel/context/ContextBoost.cpp b/src/kernel/context/ContextBoost.cpp index 71274dbadd..27f801fdd1 100644 --- a/src/kernel/context/ContextBoost.cpp +++ b/src/kernel/context/ContextBoost.cpp @@ -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_) diff --git a/src/kernel/context/ContextBoost.hpp b/src/kernel/context/ContextBoost.hpp index 687a3c18be..64456350d0 100644 --- a/src/kernel/context/ContextBoost.hpp +++ b/src/kernel/context/ContextBoost.hpp @@ -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 { diff --git a/src/kernel/context/ContextRaw.cpp b/src/kernel/context/ContextRaw.cpp index 721508c6a4..1d39323aa5 100644 --- a/src/kernel/context/ContextRaw.cpp +++ b/src/kernel/context/ContextRaw.cpp @@ -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_) diff --git a/src/kernel/context/ContextRaw.hpp b/src/kernel/context/ContextRaw.hpp index a016e98e45..2d975e70ea 100644 --- a/src/kernel/context/ContextRaw.hpp +++ b/src/kernel/context/ContextRaw.hpp @@ -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 { diff --git a/src/kernel/context/ContextSwapped.cpp b/src/kernel/context/ContextSwapped.cpp index 3bea171b3c..292cb593d2 100644 --- a/src/kernel/context/ContextSwapped.cpp +++ b/src/kernel/context/ContextSwapped.cpp @@ -187,35 +187,32 @@ void SwappedContextFactory::run_all() */ void SwappedContext::resume() { + SwappedContext* old = static_cast(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(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(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 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 diff --git a/src/kernel/context/ContextSwapped.hpp b/src/kernel/context/ContextSwapped.hpp index 5e526ce092..4c03501267 100644 --- a/src/kernel/context/ContextSwapped.hpp +++ b/src/kernel/context/ContextSwapped.hpp @@ -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 diff --git a/src/kernel/context/ContextThread.hpp b/src/kernel/context/ContextThread.hpp index 8974140b6d..a5e74f505b 100644 --- a/src/kernel/context/ContextThread.hpp +++ b/src/kernel/context/ContextThread.hpp @@ -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; diff --git a/src/kernel/context/ContextUnix.cpp b/src/kernel/context/ContextUnix.cpp index ced08e1792..c074806302 100644 --- a/src/kernel/context/ContextUnix.cpp +++ b/src/kernel/context/ContextUnix.cpp @@ -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 {