Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename instr_interface.h and mc_ignore.h to .hpp.
[simgrid.git] / src / kernel / context / ContextUnix.cpp
index 6574a74..e3df168 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -8,7 +8,7 @@
 #include "ContextUnix.hpp"
 
 #include "mc/mc.h"
-#include "src/mc/mc_ignore.h"
+#include "src/mc/mc_ignore.hpp"
 #include "src/simix/ActorImpl.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
@@ -103,7 +103,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);
-    UContext::makecontext(&this->uc_, UContext::wrapper, this);
+    UContext::make_ctx(&this->uc_, UContext::wrapper, this);
   } else {
     if (process != nullptr && maestro_context_ == nullptr)
       maestro_context_ = this;
@@ -131,11 +131,11 @@ void UContext::wrapper(int i1, int i2)
  * Makecontext expects integer arguments, we the context variable is decomposed into a serie of integers and each
  * integer is passed as argument to makecontext.
  */
-void UContext::makecontext(ucontext_t* ucp, void (*func)(int, int), UContext* arg)
+void UContext::make_ctx(ucontext_t* ucp, void (*func)(int, int), UContext* arg)
 {
   int ctx_addr[CTX_ADDR_LEN]{};
   memcpy(ctx_addr, &arg, sizeof arg);
-  ::makecontext(ucp, (void (*)())func, 2, ctx_addr[0], ctx_addr[1]);
+  makecontext(ucp, (void (*)())func, 2, ctx_addr[0], ctx_addr[1]);
 }
 
 void UContext::stop()
@@ -188,7 +188,7 @@ void SerialUContext::run_all()
 #if HAVE_THREAD_CONTEXTS
 
 simgrid::xbt::Parmap<smx_actor_t>* ParallelUContext::parmap_;
-uintptr_t ParallelUContext::threads_working_;                      /* number of threads that have started their work */
+std::atomic<uintptr_t> ParallelUContext::threads_working_;         /* number of threads that have started their work */
 xbt_os_thread_key_t ParallelUContext::worker_id_key_;              /* thread-specific storage for the thread id */
 std::vector<ParallelUContext*> ParallelUContext::workers_context_; /* space to save the worker's context
                                                                     * in each thread */
@@ -263,7 +263,7 @@ void ParallelUContext::suspend()
 void ParallelUContext::resume()
 {
   // What is my containing body?
-  uintptr_t worker_id = __sync_fetch_and_add(&threads_working_, 1);
+  uintptr_t worker_id = threads_working_.fetch_add(1, std::memory_order_relaxed);
   // Store the number of my containing body in os-thread-specific area :
   xbt_os_thread_set_specific(worker_id_key_, reinterpret_cast<void*>(worker_id));
   // Get my current soul: