From 70462345751be91c39abaa0a370ffec2bcc52467 Mon Sep 17 00:00:00 2001
From: Berenger Bramas <Berenger.Bramas@inria.fr>
Date: Fri, 2 Oct 2015 13:26:52 +0200
Subject: [PATCH] update binding functions

---
 Src/Utils/FBinding.hpp | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/Src/Utils/FBinding.hpp b/Src/Utils/FBinding.hpp
index f04df1258..09f0d91ac 100644
--- a/Src/Utils/FBinding.hpp
+++ b/Src/Utils/FBinding.hpp
@@ -17,15 +17,23 @@ namespace FBinding {
 #define FBINDING_ENABLE
 #endif
 
-inline int GetThreadBinding(){
+inline long GetThreadBinding(){
     // Mask will contain the current affinity
 #ifdef FBINDING_ENABLE
-    unsigned long mask = 0;
+    cpu_set_t mask;
+    CPU_ZERO(&mask);
     // We need the thread pid (even if we are in openmp)
     pid_t tid = (pid_t) syscall(SYS_gettid);
     // Get the affinity
     FAssertLF(sched_getaffinity(tid, sizeof(mask), (cpu_set_t*)&mask) != -1);
-    return int(mask>>1);
+
+    long cpus = 0;
+    for(size_t idxCpu = 0 ; idxCpu < sizeof(long)*8-1 ; ++idxCpu){
+        if(CPU_ISSET(idxCpu, &mask)){
+            cpus |= (1 << idxCpu);
+        }
+    }
+    return cpus;
 #endif
     return -1;
 }
-- 
GitLab