The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
sync.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <stdatomic.h>
14 #include <stdbool.h>
15 #include <stdint.h>
16 
18 typedef atomic_flag spinlock_t;
19 
24 #define spin_init(lck_p) spin_unlock(lck_p)
25 
30 #if defined(__x86_64__) || defined(__i386__)
31 #define spin_pause() __builtin_ia32_pause()
32 #else
33 #define spin_pause()
34 #endif
35 
40 #define spin_lock(lck_p) \
41 __extension__({ \
42  while(atomic_flag_test_and_set_explicit((lck_p), \
43  memory_order_acquire)) \
44  spin_pause(); \
45 })
46 
52 #define spin_trylock(lck_p) \
53  !atomic_flag_test_and_set_explicit((lck_p), memory_order_acquire)
54 
59 #define spin_unlock(lck_p) \
60  atomic_flag_clear_explicit((lck_p), memory_order_release)
61 
62 extern bool sync_thread_barrier(void);
sync_thread_barrier
bool sync_thread_barrier(void)
Synchronizes threads on a barrier.
Definition: sync.c:19
spinlock_t
atomic_flag spinlock_t
The type of a spinlock, an efficient lock primitive in contended scenarios.
Definition: sync.h:18