Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sysv contexts: remove useless indirection.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 9 Jun 2018 21:35:13 +0000 (23:35 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 10 Jun 2018 17:02:08 +0000 (19:02 +0200)
src/kernel/context/ContextUnix.cpp
src/kernel/context/ContextUnix.hpp

index e3df168..dcb9088 100644 (file)
@@ -21,24 +21,6 @@ constexpr int CTX_ADDR_LEN = 2;
 static_assert(sizeof(simgrid::kernel::context::UContext*) <= CTX_ADDR_LEN * sizeof(int),
               "Ucontexts are not supported on this arch yet");
 
 static_assert(sizeof(simgrid::kernel::context::UContext*) <= CTX_ADDR_LEN * sizeof(int),
               "Ucontexts are not supported on this arch yet");
 
-// The name of this function is currently hardcoded in the code (as string).
-// Do not change it without fixing those references as well.
-static void smx_ctx_sysv_wrapper(int i1, int i2)
-{
-  // Rebuild the Context* pointer from the integers:
-  int ctx_addr[CTX_ADDR_LEN] = {i1, i2};
-  simgrid::kernel::context::UContext* context;
-  memcpy(&context, ctx_addr, sizeof context);
-
-  try {
-    (*context)();
-    context->Context::stop();
-  } catch (simgrid::kernel::context::Context::StopRequest const&) {
-    XBT_DEBUG("Caught a StopRequest");
-  }
-  context->suspend();
-}
-
 namespace simgrid {
 namespace kernel {
 namespace context {
 namespace simgrid {
 namespace kernel {
 namespace context {
@@ -103,7 +85,7 @@ UContext::UContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_fun
     this->uc_.uc_link = nullptr;
     this->uc_.uc_stack.ss_sp   = sg_makecontext_stack_addr(this->stack_);
     this->uc_.uc_stack.ss_size = sg_makecontext_stack_size(smx_context_usable_stack_size);
     this->uc_.uc_link = nullptr;
     this->uc_.uc_stack.ss_sp   = sg_makecontext_stack_addr(this->stack_);
     this->uc_.uc_stack.ss_size = sg_makecontext_stack_size(smx_context_usable_stack_size);
-    UContext::make_ctx(&this->uc_, UContext::wrapper, this);
+    UContext::make_ctx(&this->uc_, UContext::smx_ctx_sysv_wrapper, this);
   } else {
     if (process != nullptr && maestro_context_ == nullptr)
       maestro_context_ = this;
   } else {
     if (process != nullptr && maestro_context_ == nullptr)
       maestro_context_ = this;
@@ -121,9 +103,22 @@ UContext::~UContext()
   SIMIX_context_stack_delete(this->stack_);
 }
 
   SIMIX_context_stack_delete(this->stack_);
 }
 
-void UContext::wrapper(int i1, int i2)
+// The name of this function is currently hardcoded in the code (as string).
+// Do not change it without fixing those references as well.
+void UContext::smx_ctx_sysv_wrapper(int i1, int i2)
 {
 {
-  smx_ctx_sysv_wrapper(i1, i2);
+  // Rebuild the Context* pointer from the integers:
+  int ctx_addr[CTX_ADDR_LEN] = {i1, i2};
+  simgrid::kernel::context::UContext* context;
+  memcpy(&context, ctx_addr, sizeof context);
+
+  try {
+    (*context)();
+    context->Context::stop();
+  } catch (simgrid::kernel::context::Context::StopRequest const&) {
+    XBT_DEBUG("Caught a StopRequest");
+  }
+  context->suspend();
 }
 
 /** A better makecontext
 }
 
 /** A better makecontext
index 6ad0412..8bc8ce6 100644 (file)
@@ -41,7 +41,7 @@ private:
   void* stack_ = nullptr; /* the thread stack */
   ucontext_t uc_;         /* the ucontext that executes the code */
 
   void* stack_ = nullptr; /* the thread stack */
   ucontext_t uc_;         /* the ucontext that executes the code */
 
-  static void wrapper(int, int);
+  static void smx_ctx_sysv_wrapper(int, int);
   static void make_ctx(ucontext_t* ucp, void (*func)(int, int), UContext* arg);
 };
 
   static void make_ctx(ucontext_t* ucp, void (*func)(int, int), UContext* arg);
 };