12 #ifndef _H_SST_CORE_INTERPROCESS_MUTEX
13 #define _H_SST_CORE_INTERPROCESS_MUTEX
20 namespace Interprocess {
22 #define SST_CORE_INTERPROCESS_LOCKED 1
23 #define SST_CORE_INTERPROCESS_UNLOCKED 0
29 lockVal = SST_CORE_INTERPROCESS_UNLOCKED;
32 void processorPause(
int currentCount) {
33 if( currentCount < 64 ) {
34 #if defined(__x86_64__)
35 asm volatile (
"pause" : : :
"memory");
39 }
else if( currentCount < 256 ) {
42 struct timespec sleepPeriod;
43 sleepPeriod.tv_sec = 0;
44 sleepPeriod.tv_nsec = 100;
46 struct timespec interPeriod;
47 nanosleep(&sleepPeriod, &interPeriod);
54 while( ! __sync_bool_compare_and_swap( &lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED) ) {
55 processorPause(loop_counter);
61 lockVal = SST_CORE_INTERPROCESS_UNLOCKED;
66 return __sync_bool_compare_and_swap( &lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED );
Definition: sstmutex.h:25