Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make SIMIX_context_self() useless and use Context::self() instead
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 5 Jan 2019 16:10:34 +0000 (17:10 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 5 Jan 2019 16:10:34 +0000 (17:10 +0100)
src/bindings/java/jmsg.cpp
src/kernel/context/Context.cpp
src/kernel/context/Context.hpp
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextUnix.cpp
src/s4u/s4u_Actor.cpp
src/simix/ActorImpl.cpp

index 7987779..75b71f8 100644 (file)
@@ -50,7 +50,7 @@ JavaVM *__java_vm = nullptr;
 JNIEnv *get_current_thread_env()
 {
   using simgrid::kernel::context::JavaContext;
 JNIEnv *get_current_thread_env()
 {
   using simgrid::kernel::context::JavaContext;
-  JavaContext* ctx = static_cast<JavaContext*>(SIMIX_context_self());
+  JavaContext* ctx = static_cast<JavaContext*>(simgrid::kernel::context::Context::self());
   return ctx->jenv_;
 }
 
   return ctx->jenv_;
 }
 
@@ -269,7 +269,8 @@ static void run_jprocess(JNIEnv *env, jobject jprocess)
 static int java_main(int argc, char *argv[])
 {
   JNIEnv *env = get_current_thread_env();
 static int java_main(int argc, char *argv[])
 {
   JNIEnv *env = get_current_thread_env();
-  simgrid::kernel::context::JavaContext* context = static_cast<simgrid::kernel::context::JavaContext*>(SIMIX_context_self());
+  simgrid::kernel::context::JavaContext* context =
+      static_cast<simgrid::kernel::context::JavaContext*>(simgrid::kernel::context::Context::self());
 
   //Change the "." in class name for "/".
   std::string arg0 = argv[0];
 
   //Change the "." in class name for "/".
   std::string arg0 = argv[0];
@@ -315,7 +316,8 @@ namespace context {
 void java_main_jprocess(jobject jprocess)
 {
   JNIEnv *env = get_current_thread_env();
 void java_main_jprocess(jobject jprocess)
 {
   JNIEnv *env = get_current_thread_env();
-  simgrid::kernel::context::JavaContext* context = static_cast<simgrid::kernel::context::JavaContext*>(SIMIX_context_self());
+  simgrid::kernel::context::JavaContext* context =
+      static_cast<simgrid::kernel::context::JavaContext*>(simgrid::kernel::context::Context::self());
   context->jprocess_                             = jprocess;
   jprocess_bind(context->jprocess_, MSG_process_self(), env);
 
   context->jprocess_                             = jprocess;
   jprocess_bind(context->jprocess_, MSG_process_self(), env);
 
index 8a72534..63321eb 100644 (file)
@@ -34,7 +34,7 @@ ContextFactoryInitializer factory_initializer = nullptr;
 
 ContextFactory::~ContextFactory() = default;
 
 
 ContextFactory::~ContextFactory() = default;
 
-static thread_local smx_context_t smx_current_context;
+static thread_local smx_context_t smx_current_context = nullptr;
 Context* Context::self()
 {
   return smx_current_context;
 Context* Context::self()
 {
   return smx_current_context;
@@ -77,7 +77,11 @@ Context::Context(std::function<void()> code, void_pfn_smxprocess_t cleanup_func,
     set_current(this);
 }
 
     set_current(this);
 }
 
-Context::~Context() = default;
+Context::~Context()
+{
+  if (self() == this)
+    set_current(nullptr);
+}
 
 void Context::stop()
 {
 
 void Context::stop()
 {
@@ -99,12 +103,3 @@ void SIMIX_context_runall()
 {
   simix_global->context_factory->run_all();
 }
 {
   simix_global->context_factory->run_all();
 }
-
-/** @brief returns the current running context */
-smx_context_t SIMIX_context_self()
-{
-  if (simix_global && simix_global->context_factory)
-    return simgrid::kernel::context::Context::self();
-  else
-    return nullptr;
-}
index 5219608..6271a8b 100644 (file)
@@ -145,8 +145,6 @@ XBT_PUBLIC_DATA char sigsegv_stack[SIGSTKSZ];
 
 /** @brief Executes all the processes to run (in parallel if possible). */
 XBT_PRIVATE void SIMIX_context_runall();
 
 /** @brief Executes all the processes to run (in parallel if possible). */
 XBT_PRIVATE void SIMIX_context_runall();
-/** @brief returns the current running context */
-XBT_PUBLIC smx_context_t SIMIX_context_self(); // public because it's used in simgrid-java
 
 XBT_PRIVATE void *SIMIX_context_stack_new();
 XBT_PRIVATE void SIMIX_context_stack_delete(void *stack);
 
 XBT_PRIVATE void *SIMIX_context_stack_new();
 XBT_PRIVATE void SIMIX_context_stack_delete(void *stack);
index c745dff..07bb785 100644 (file)
@@ -231,7 +231,7 @@ void ParallelBoostContext::resume()
 {
   worker_id_ = threads_working_.fetch_add(1, std::memory_order_relaxed);
 
 {
   worker_id_ = threads_working_.fetch_add(1, std::memory_order_relaxed);
 
-  ParallelBoostContext* worker_context = static_cast<ParallelBoostContext*>(SIMIX_context_self());
+  ParallelBoostContext* worker_context = static_cast<ParallelBoostContext*>(self());
   workers_context_[worker_id_]         = worker_context;
 
   Context::set_current(this);
   workers_context_[worker_id_]         = worker_context;
 
   Context::set_current(this);
index d98470b..a0c065f 100644 (file)
@@ -374,7 +374,7 @@ void ParallelRawContext::suspend()
 void ParallelRawContext::resume()
 {
   worker_id_                         = threads_working_.fetch_add(1, std::memory_order_relaxed);
 void ParallelRawContext::resume()
 {
   worker_id_                         = threads_working_.fetch_add(1, std::memory_order_relaxed);
-  ParallelRawContext* worker_context = static_cast<ParallelRawContext*>(SIMIX_context_self());
+  ParallelRawContext* worker_context = static_cast<ParallelRawContext*>(self());
   workers_context_[worker_id_]       = worker_context;
   XBT_DEBUG("Saving worker stack %zu", worker_id_);
   Context::set_current(this);
   workers_context_[worker_id_]       = worker_context;
   XBT_DEBUG("Saving worker stack %zu", worker_id_);
   Context::set_current(this);
index 5dc49b5..e264144 100644 (file)
@@ -266,7 +266,7 @@ void ParallelUContext::resume()
   // What is my containing body? Store its number in os-thread-specific area :
   worker_id_ = threads_working_.fetch_add(1, std::memory_order_relaxed);
   // Get my current soul:
   // What is my containing body? Store its number in os-thread-specific area :
   worker_id_ = threads_working_.fetch_add(1, std::memory_order_relaxed);
   // Get my current soul:
-  ParallelUContext* worker_context = static_cast<ParallelUContext*>(SIMIX_context_self());
+  ParallelUContext* worker_context = static_cast<ParallelUContext*>(self());
   // Write down that this soul is hosted in that body (for now)
   workers_context_[worker_id_] = worker_context;
   // Write in simix that I switched my soul
   // Write down that this soul is hosted in that body (for now)
   workers_context_[worker_id_] = worker_context;
   // Write in simix that I switched my soul
index 83ea571..f693e25 100644 (file)
@@ -31,7 +31,7 @@ simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> s4u::Actor::on_destruction;
 // ***** Actor creation *****
 ActorPtr Actor::self()
 {
 // ***** Actor creation *****
 ActorPtr Actor::self()
 {
-  smx_context_t self_context = SIMIX_context_self();
+  smx_context_t self_context = simgrid::kernel::context::Context::self();
   if (self_context == nullptr)
     return simgrid::s4u::ActorPtr();
 
   if (self_context == nullptr)
     return simgrid::s4u::ActorPtr();
 
index 4d494cd..f9bc844 100644 (file)
@@ -34,7 +34,7 @@ unsigned long simix_process_maxpid = 0;
  */
 smx_actor_t SIMIX_process_self()
 {
  */
 smx_actor_t SIMIX_process_self()
 {
-  smx_context_t self_context = SIMIX_context_self();
+  smx_context_t self_context = simgrid::kernel::context::Context::self();
 
   return (self_context != nullptr) ? self_context->process() : nullptr;
 }
 
   return (self_context != nullptr) ? self_context->process() : nullptr;
 }
@@ -429,7 +429,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn
 
 void SIMIX_process_detach()
 {
 
 void SIMIX_process_detach()
 {
-  auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(SIMIX_context_self());
+  auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(simgrid::kernel::context::Context::self());
   if (context == nullptr)
     xbt_die("Not a suitable context");
 
   if (context == nullptr)
     xbt_die("Not a suitable context");