Commit 70462345 authored by BRAMAS Berenger's avatar BRAMAS Berenger

update binding functions

parent 29204aaa
...@@ -17,15 +17,23 @@ namespace FBinding { ...@@ -17,15 +17,23 @@ namespace FBinding {
#define FBINDING_ENABLE #define FBINDING_ENABLE
#endif #endif
inline int GetThreadBinding(){ inline long GetThreadBinding(){
// Mask will contain the current affinity // Mask will contain the current affinity
#ifdef FBINDING_ENABLE #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) // We need the thread pid (even if we are in openmp)
pid_t tid = (pid_t) syscall(SYS_gettid); pid_t tid = (pid_t) syscall(SYS_gettid);
// Get the affinity // Get the affinity
FAssertLF(sched_getaffinity(tid, sizeof(mask), (cpu_set_t*)&mask) != -1); 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 #endif
return -1; return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment