12 #ifndef SST_CORE_INTERPROCESS_MUTEX_H 13 #define SST_CORE_INTERPROCESS_MUTEX_H 20 namespace Interprocess {
22 #define SST_CORE_INTERPROCESS_LOCKED 1 23 #define SST_CORE_INTERPROCESS_UNLOCKED 0 29 SSTMutex() { lockVal = SST_CORE_INTERPROCESS_UNLOCKED; }
31 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");
42 else if ( currentCount < 256 ) {
46 struct timespec sleepPeriod;
47 sleepPeriod.tv_sec = 0;
48 sleepPeriod.tv_nsec = 100;
50 struct timespec interPeriod;
51 nanosleep(&sleepPeriod, &interPeriod);
60 !__sync_bool_compare_and_swap(&lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED) ) {
61 processorPause(loop_counter);
68 lockVal = SST_CORE_INTERPROCESS_UNLOCKED;
74 return __sync_bool_compare_and_swap(&lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED);
85 #endif // SST_CORE_INTERPROCESS_MUTEX_H
Definition: sstmutex.h:25