Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More cleanup in contexts' stop().
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 22 Sep 2017 22:21:41 +0000 (00:21 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 23 Sep 2017 22:43:10 +0000 (00:43 +0200)
Call Context::stop() at upper level: save an exception, and hopefully fix
MC tests on FreeBSD, even if I don't really understand what's going wrong.

src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextBoost.hpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextThread.cpp
src/kernel/context/ContextUnix.cpp

index d597a45..fa2faf1 100644 (file)
@@ -30,7 +30,6 @@ public:
       void_pfn_smxprocess_t cleanup_func,
       smx_actor_t process)
     : BoostContext(std::move(code), cleanup_func, process) {}
-  void stop() override;
   void suspend() override;
 };
 
@@ -41,7 +40,6 @@ public:
       void_pfn_smxprocess_t cleanup_func,
       smx_actor_t process)
     : BoostContext(std::move(code), cleanup_func, process) {}
-  void stop() override;
   void suspend() override;
   void resume() override;
 };
@@ -137,8 +135,8 @@ void BoostContext::smx_ctx_boost_wrapper(BoostContext::ctx_arg_type arg)
 #endif
   try {
     (*context)();
-    context->stop();
-  } catch (const StopRequest&) {
+    context->Context::stop();
+  } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   }
   context->suspend();
@@ -199,6 +197,12 @@ BoostContext::~BoostContext()
 
 // BoostSerialContext
 
+void BoostContext::stop()
+{
+  Context::stop();
+  throw StopRequest();
+}
+
 void BoostContext::resume()
 {
   SIMIX_context_set_current(this);
@@ -225,12 +229,6 @@ void BoostSerialContext::suspend()
   smx_ctx_boost_jump_fcontext(this, next_context);
 }
 
-void BoostSerialContext::stop()
-{
-  BoostContext::stop();
-  throw StopRequest();
-}
-
 // BoostParallelContext
 
 #if HAVE_THREAD_CONTEXTS
@@ -252,12 +250,6 @@ void BoostParallelContext::suspend()
   smx_ctx_boost_jump_fcontext(this, next_context);
 }
 
-void BoostParallelContext::stop()
-{
-  BoostContext::stop();
-  throw StopRequest();
-}
-
 void BoostParallelContext::resume()
 {
   uintptr_t worker_id = __sync_fetch_and_add(&threads_working_, 1);
index 0c6a35b..d5eca56 100644 (file)
@@ -60,6 +60,7 @@ public:
           void_pfn_smxprocess_t cleanup_func,
           smx_actor_t process);
   ~BoostContext() override;
+  void stop() override;
   virtual void resume();
 private:
   static void wrapper(int first, ...);
index 00c6008..244fdd4 100644 (file)
@@ -293,8 +293,8 @@ void RawContext::wrapper(void* arg)
   RawContext* context = static_cast<RawContext*>(arg);
   try {
     (*context)();
-    context->stop();
-  } catch (StopRequest) {
+    context->Context::stop();
+  } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   }
   context->suspend();
index 395e730..8e9ee72 100644 (file)
@@ -153,8 +153,8 @@ void *ThreadContext::wrapper(void *param)
 
   try {
     (*context)();
-    context->stop();
-  } catch (StopRequest) {
+    context->Context::stop();
+  } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   }
 
index 5a7148d..0ee4c14 100644 (file)
@@ -81,6 +81,7 @@ public:
   UContext(std::function<void()>  code,
     void_pfn_smxprocess_t cleanup_func, smx_actor_t process);
   ~UContext() override;
+  void stop() override;
 };
 
 class SerialUContext : public UContext {
@@ -89,7 +90,6 @@ public:
       void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
     : UContext(std::move(code), cleanup_func, process)
   {}
-  void stop() override;
   void suspend() override;
   void resume();
 };
@@ -100,7 +100,6 @@ public:
       void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
     : UContext(std::move(code), cleanup_func, process)
   {}
-  void stop() override;
   void suspend() override;
   void resume();
 };
@@ -230,6 +229,11 @@ UContext::~UContext()
   SIMIX_context_stack_delete(this->stack_);
 }
 
+void UContext::stop()
+{
+  Context::stop();
+  throw StopRequest();
+}
 }}} // namespace simgrid::kernel::context
 
 static void smx_ctx_sysv_wrapper(int first, ...)
@@ -249,8 +253,8 @@ static void smx_ctx_sysv_wrapper(int first, ...)
 
   try {
     (*context)();
-    context->stop();
-  } catch (simgrid::kernel::context::Context::StopRequest) {
+    context->Context::stop();
+  } catch (simgrid::kernel::context::Context::StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
   }
   context->suspend();
@@ -260,12 +264,6 @@ namespace simgrid {
 namespace kernel {
 namespace context {
 
-void SerialUContext::stop()
-{
-  Context::stop();
-  throw StopRequest();
-}
-
 void SerialUContext::suspend()
 {
   /* determine the next context */
@@ -293,12 +291,6 @@ void SerialUContext::resume()
   swapcontext(&static_cast<SerialUContext*>(sysv_maestro_context)->uc_, &this->uc_);
 }
 
-void ParallelUContext::stop()
-{
-  UContext::stop();
-  throw StopRequest();
-}
-
 /** Run one particular simulated process on the current thread. */
 void ParallelUContext::resume()
 {