3 #ifndef _H_SST_CORE_INTERPROCESS_MUTEX
4 #define _H_SST_CORE_INTERPROCESS_MUTEX
11 namespace Interprocess {
13 #define SST_CORE_INTERPROCESS_LOCKED 1
14 #define SST_CORE_INTERPROCESS_UNLOCKED 0
20 lockVal = SST_CORE_INTERPROCESS_UNLOCKED;
23 void processorPause(
int currentCount) {
24 if( currentCount < 64 ) {
25 #if defined(__x86_64__)
26 asm volatile (
"pause" : : :
"memory");
30 }
else if( currentCount < 256 ) {
33 struct timespec sleepPeriod;
34 sleepPeriod.tv_sec = 0;
35 sleepPeriod.tv_nsec = 100;
37 struct timespec interPeriod;
38 nanosleep(&sleepPeriod, &interPeriod);
45 while( ! __sync_bool_compare_and_swap( &lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED) ) {
46 processorPause(loop_counter);
52 lockVal = SST_CORE_INTERPROCESS_UNLOCKED;
57 return __sync_bool_compare_and_swap( &lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED );
Definition: sstmutex.h:16