Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move ContextFactory::self() into Context::self() and tidy it up
[simgrid.git] / src / include / xbt / parmap.hpp
index b5b72de..c589364 100644 (file)
@@ -15,6 +15,7 @@
 #include <boost/optional.hpp>
 #include <condition_variable>
 #include <mutex>
+#include <thread>
 
 #if HAVE_FUTEX_H
 #include <linux/futex.h>
@@ -164,19 +165,15 @@ template <typename T> Parmap<T>::Parmap(unsigned num_workers, e_xbt_parmap_mode_
 
   /* Create the pool of worker threads */
   this->workers[0] = nullptr;
-#if HAVE_PTHREAD_SETAFFINITY
-  int core_bind = 0;
-#endif
+  unsigned int core_bind = 0;
   for (unsigned i = 1; i < num_workers; i++) {
     ThreadData* data = new ThreadData(*this, i);
-    this->workers[i] = xbt_os_thread_create(nullptr, worker_main, data, nullptr);
-#if HAVE_PTHREAD_SETAFFINITY
+    this->workers[i] = xbt_os_thread_create(worker_main, data);
     xbt_os_thread_bind(this->workers[i], core_bind);
-    if (core_bind != xbt_os_get_numcores() - 1)
+    if (core_bind != std::thread::hardware_concurrency() - 1)
       core_bind++;
     else
       core_bind = 0;
-#endif
   }
 }
 
@@ -284,7 +281,7 @@ template <typename T> void* Parmap<T>::worker_main(void* arg)
   Parmap<T>& parmap     = data->parmap;
   unsigned round        = 0;
   smx_context_t context = SIMIX_context_new(std::function<void()>(), nullptr, nullptr);
-  SIMIX_context_set_current(context);
+  kernel::context::Context::set_current(context);
 
   XBT_CDEBUG(xbt_parmap, "New worker thread created");
 
@@ -411,7 +408,7 @@ template <typename T> void Parmap<T>::BusyWaitSynchro::master_signal()
 template <typename T> void Parmap<T>::BusyWaitSynchro::master_wait()
 {
   while (__atomic_load_n(&this->parmap.thread_counter, __ATOMIC_SEQ_CST) < this->parmap.num_workers) {
-    xbt_os_thread_yield();
+    std::this_thread::yield();
   }
 }
 
@@ -424,7 +421,7 @@ template <typename T> void Parmap<T>::BusyWaitSynchro::worker_wait(unsigned roun
 {
   /* wait for more work */
   while (__atomic_load_n(&this->parmap.work_round, __ATOMIC_SEQ_CST) != round) {
-    xbt_os_thread_yield();
+    std::this_thread::yield();
   }
 }