12 #ifndef SST_CORE_INTERPROCESS_MUTEX_H 13 #define SST_CORE_INTERPROCESS_MUTEX_H 20 #define SST_CORE_INTERPROCESS_LOCKED 1 21 #define SST_CORE_INTERPROCESS_UNLOCKED 0 27 SSTMutex() { lockVal = SST_CORE_INTERPROCESS_UNLOCKED; }
29 void processorPause(
int currentCount)
31 if ( currentCount < 64 ) {
32 #if defined(__x86_64__) 33 __asm__ __volatile__(
"pause" : : :
"memory");
34 #elif (defined(__arm__) || defined(__aarch64__)) 35 __asm__ __volatile__(
"yield");
40 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);
58 !__sync_bool_compare_and_swap(&lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED) ) {
59 processorPause(loop_counter);
66 lockVal = SST_CORE_INTERPROCESS_UNLOCKED;
72 return __sync_bool_compare_and_swap(&lockVal, SST_CORE_INTERPROCESS_UNLOCKED, SST_CORE_INTERPROCESS_LOCKED);
81 #endif // SST_CORE_INTERPROCESS_MUTEX_H Definition: circularBuffer.h:20
Definition: sstmutex.h:23