Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / src / include / xbt / parmap.hpp
index e28e78a..4e073a1 100644 (file)
@@ -10,7 +10,6 @@
 
 #include "src/internal_config.h" // HAVE_FUTEX_H
 #include "src/kernel/context/Context.hpp"
-#include "xbt/xbt_os_thread.h"
 
 #include <boost/optional.hpp>
 #include <condition_variable>
 #include <sys/syscall.h>
 #endif
 
+#if HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+
 XBT_LOG_EXTERNAL_CATEGORY(xbt_parmap);
 
 namespace simgrid {
@@ -159,7 +162,7 @@ template <typename T> Parmap<T>::Parmap(unsigned num_workers, e_xbt_parmap_mode_
   /* Initialize the thread pool data structure */
   this->status      = PARMAP_WORK;
   this->work_round  = 0;
-  this->workers.reserve(num_workers);
+  this->workers.resize(num_workers);
   this->num_workers = num_workers;
   this->synchro     = new_synchro(mode);
 
@@ -172,11 +175,17 @@ template <typename T> Parmap<T>::Parmap(unsigned num_workers, e_xbt_parmap_mode_
 
     /* Bind the worker to a core if possible */
 #if HAVE_PTHREAD_SETAFFINITY
-    pthread_t pthread = this->workers[i]->native_handle();
+#if HAVE_PTHREAD_NP_H /* FreeBSD ? */
+    cpuset_t cpuset;
+    size_t size = sizeof(cpuset_t);
+#else /* Linux ? */
     cpu_set_t cpuset;
+    size_t size = sizeof(cpu_set_t);
+#endif
+    pthread_t pthread = this->workers[i]->native_handle();
     CPU_ZERO(&cpuset);
     CPU_SET(core_bind, &cpuset);
-    pthread_setaffinity_np(pthread, sizeof(cpu_set_t), &cpuset);
+    pthread_setaffinity_np(pthread, size, &cpuset);
     if (core_bind != std::thread::hardware_concurrency() - 1)
       core_bind++;
     else
@@ -196,7 +205,6 @@ template <typename T> Parmap<T>::~Parmap()
   for (unsigned i = 1; i < num_workers; i++)
     workers[i]->join();
 
-  workers.clear();
   delete synchro;
 }