Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
unify how threaded and parallelisable context factories find context_self
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 5 Jan 2019 01:02:31 +0000 (02:02 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 5 Jan 2019 01:02:31 +0000 (02:02 +0100)
src/bindings/java/JavaContext.cpp
src/bindings/java/JavaContext.hpp
src/bindings/java/jmsg.cpp
src/kernel/context/Context.hpp
src/kernel/context/ContextThread.cpp
src/kernel/context/ContextThread.hpp

index 5fe1c0c..937f707 100644 (file)
@@ -34,11 +34,6 @@ JavaContextFactory::JavaContextFactory(): ContextFactory("JavaContextFactory")
 
 JavaContextFactory::~JavaContextFactory()=default;
 
-JavaContext* JavaContextFactory::self()
-{
-  return static_cast<JavaContext*>(xbt_os_thread_get_extra_data());
-}
-
 JavaContext* JavaContextFactory::create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup_fun,
                                                 smx_actor_t actor)
 {
@@ -58,7 +53,7 @@ JavaContext::JavaContext(std::function<void()> code, void_pfn_smxprocess_t clean
 
 void JavaContext::start_hook()
 {
-  xbt_os_thread_set_extra_data(this); // We need to attach it also for maestro, in contrary to our ancestor
+  SIMIX_context_set_current(this); // We need to attach it also for maestro, in contrary to our ancestor
 
   //Attach the thread to the JVM
   JNIEnv *env;
index 0a07f01..5458cc1 100644 (file)
@@ -45,7 +45,6 @@ class JavaContextFactory : public simgrid::kernel::context::ContextFactory {
 public:
   JavaContextFactory();
   ~JavaContextFactory() override;
-  JavaContext* self() override;
   JavaContext* create_context(std::function<void()> code,
     void_pfn_smxprocess_t, smx_actor_t process) override;
   void run_all() override;
index 5ff074a..7987779 100644 (file)
@@ -50,7 +50,7 @@ JavaVM *__java_vm = nullptr;
 JNIEnv *get_current_thread_env()
 {
   using simgrid::kernel::context::JavaContext;
-  JavaContext* ctx = static_cast<JavaContext*>(xbt_os_thread_get_extra_data());
+  JavaContext* ctx = static_cast<JavaContext*>(SIMIX_context_self());
   return ctx->jenv_;
 }
 
index c543f41..0f4a2b0 100644 (file)
@@ -35,7 +35,7 @@ public:
 
   virtual void run_all() = 0;
   /** @brief Returns the current context of this thread. */
-  virtual Context* self();
+  Context* self();
   std::string const& name() const { return name_; }
 
 protected:
index ab20215..c93e361 100644 (file)
@@ -78,7 +78,7 @@ ThreadContext::ThreadContext(std::function<void()> code, void_pfn_smxprocess_t c
 
   /* Otherwise, we attach to the current thread */
   else {
-    xbt_os_thread_set_extra_data(this);
+    SIMIX_context_set_current(this);
   }
 }
 
@@ -91,6 +91,7 @@ ThreadContext::~ThreadContext()
 void *ThreadContext::wrapper(void *param)
 {
   ThreadContext* context = static_cast<ThreadContext*>(param);
+  SIMIX_context_set_current(context);
 
 #ifndef WIN32
   /* Install alternate signal stack, for SIGSEGV handler. */
@@ -177,7 +178,7 @@ void ThreadContext::attach_stop()
   ThreadContext* maestro = (ThreadContext*)simix_global->maestro_process->context_;
   maestro->end_.acquire();
 
-  xbt_os_thread_set_extra_data(nullptr);
+  SIMIX_context_set_current(nullptr);
 }
 
 // SerialThreadContext
index 5024b6f..1f9d06e 100644 (file)
@@ -87,7 +87,6 @@ public:
     return create_context(std::move(code), cleanup_func, process, maestro);
   }
   void run_all() override;
-  ThreadContext* self() override { return static_cast<ThreadContext*>(xbt_os_thread_get_extra_data()); }
 
   // Optional methods:
   ThreadContext* attach(void_pfn_smxprocess_t cleanup_func, smx_actor_t process) override