Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ThreadContext: wrapper and maestro_wrapper are nearly the same. Merge.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Oct 2017 19:46:10 +0000 (21:46 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Oct 2017 19:50:19 +0000 (21:50 +0200)
src/kernel/context/ContextThread.cpp
src/kernel/context/ContextThread.hpp

index 4eac4a5..8be0edf 100644 (file)
@@ -108,10 +108,7 @@ ThreadContext::ThreadContext(std::function<void()> code, void_pfn_smxprocess_t c
     /* create and start the process */
     /* NOTE: The first argument to xbt_os_thread_create used to be the process *
     * name, but now the name is stored at SIMIX level, so we pass a null  */
-    this->thread_ =
-      xbt_os_thread_create(nullptr,
-        maestro ? &ThreadContext::maestro_wrapper : &ThreadContext::wrapper,
-        this, this);
+    this->thread_ = xbt_os_thread_create(nullptr, ThreadContext::wrapper, this, this);
     /* wait the starting of the newly created process */
     xbt_os_sem_acquire(this->end_);
   }
@@ -144,48 +141,20 @@ void *ThreadContext::wrapper(void *param)
   stack.ss_flags = 0;
   sigaltstack(&stack, nullptr);
 #endif
-  /* Tell the maestro we are starting, and wait for its green light */
+  // Tell the caller (normally the maestro) we are starting, and wait for its green light
   xbt_os_sem_release(context->end_);
-
   context->start();
 
   try {
     (*context)();
-    context->Context::stop();
+    if (not context->is_maestro_) // really?
+      context->Context::stop();
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
+    xbt_assert(not context->is_maestro_, "I'm not supposed to be maestro here.");
   }
 
-  // Signal to the maestro that it has finished:
-  context->yield();
-
-#ifndef WIN32
-  stack.ss_flags = SS_DISABLE;
-  sigaltstack(&stack, nullptr);
-#endif
-  return nullptr;
-}
-
-void *ThreadContext::maestro_wrapper(void *param)
-{
-  ThreadContext* context = static_cast<ThreadContext*>(param);
-
-#ifndef WIN32
-  /* Install alternate signal stack, for SIGSEGV handler. */
-  stack_t stack;
-  stack.ss_sp = sigsegv_stack;
-  stack.ss_size = sizeof sigsegv_stack;
-  stack.ss_flags = 0;
-  sigaltstack(&stack, nullptr);
-#endif
-  /* Tell the caller we are starting */
-  xbt_os_sem_release(context->end_);
-
-  // Wait for the caller to give control back to us:
-  context->start();
-  (*context)();
-
-  // Tell main that we have finished:
+  // Signal to the caller (normally the maestro) that we have finished:
   context->yield();
 
 #ifndef WIN32
index 62d8191..7ce8de5 100644 (file)
@@ -38,7 +38,6 @@ private:
   bool is_maestro_;
 
   static void* wrapper(void *param);
-  static void* maestro_wrapper(void *param);
 public:
   void start();
   void yield();