Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
enum class values should be UPPER_CASE
[simgrid.git] / src / kernel / context / ContextBoost.cpp
index bf96864..9184386 100644 (file)
@@ -1,12 +1,10 @@
-/* Copyright (c) 2015-2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2015-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. */
 
 #include "ContextBoost.hpp"
-
-#include <utility>
-#include <xbt/log.h>
+#include "src/simix/smx_private.hpp"
 
 #if HAVE_SANITIZE_ADDRESS_FIBER_SUPPORT
 #include <sanitizer/asan_interface.h>
@@ -177,7 +175,7 @@ void SerialBoostContext::suspend()
     XBT_DEBUG("No more process to run");
     next_context = static_cast<SerialBoostContext*>(BoostContext::getMaestro());
   }
-  SIMIX_context_set_current(static_cast<smx_context_t>(next_context));
+  SIMIX_context_set_current(next_context);
   BoostContext::swap(this, next_context);
 }
 
@@ -202,7 +200,7 @@ void SerialBoostContext::run_all()
 #if HAVE_THREAD_CONTEXTS
 
 simgrid::xbt::Parmap<smx_actor_t>* ParallelBoostContext::parmap_;
-uintptr_t ParallelBoostContext::threads_working_;
+std::atomic<uintptr_t> ParallelBoostContext::threads_working_;
 xbt_os_thread_key_t ParallelBoostContext::worker_id_key_;
 std::vector<ParallelBoostContext*> ParallelBoostContext::workers_context_;
 
@@ -225,12 +223,12 @@ void ParallelBoostContext::finalize()
 void ParallelBoostContext::run_all()
 {
   threads_working_ = 0;
-  if (not parmap_)
+  if (parmap_ == nullptr)
     parmap_ = new simgrid::xbt::Parmap<smx_actor_t>(SIMIX_context_get_nthreads(), SIMIX_context_get_parallel_mode());
   parmap_->apply(
       [](smx_actor_t process) {
         ParallelBoostContext* context = static_cast<ParallelBoostContext*>(process->context);
-        return context->resume();
+        context->resume();
       },
       simix_global->process_to_run);
 }
@@ -254,11 +252,11 @@ void ParallelBoostContext::suspend()
 
 void ParallelBoostContext::resume()
 {
-  uintptr_t worker_id = __sync_fetch_and_add(&threads_working_, 1);
+  uintptr_t worker_id = threads_working_.fetch_add(1, std::memory_order_relaxed);
   xbt_os_thread_set_specific(worker_id_key_, reinterpret_cast<void*>(worker_id));
 
   ParallelBoostContext* worker_context = static_cast<ParallelBoostContext*>(SIMIX_context_self());
-  workers_context_[worker_id] = worker_context;
+  workers_context_[worker_id]          = worker_context;
 
   SIMIX_context_set_current(this);
   BoostContext::swap(worker_context, this);