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");
36 #elif ( defined(__arm__) || defined(__aarch64__) )
37 __asm__ __volatile__ (
"yield");
41 }
else if( currentCount < 256 ) {
44 struct timespec sleepPeriod;
45 sleepPeriod.tv_sec = 0;
46 sleepPeriod.tv_nsec = 100;
48 struct timespec interPeriod;
49 nanosleep(&sleepPeriod, &interPeriod);
56 while( ! __sync_bool_compare_and_swap( &lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED) ) {
57 processorPause(loop_counter);
63 lockVal = SST_CORE_INTERPROCESS_UNLOCKED;
68 return __sync_bool_compare_and_swap( &lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED );
Definition: sstmutex.h:25