Easier Synchronization primitives.
More...
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
|
#define | spin_init(lck_p) spin_unlock(lck_p) |
| Initializes a spinlock. More...
|
|
#define | spin_pause() |
| Tells the compiler that we are inside a spin loop.
|
|
#define | spin_lock(lck_p) |
| Locks a spinlock. More...
|
|
#define | spin_trylock(lck_p) !atomic_flag_test_and_set_explicit((lck_p), memory_order_acquire) |
| Executes the trylock operation on a spinlock. More...
|
|
#define | spin_unlock(lck_p) atomic_flag_clear_explicit((lck_p), memory_order_release) |
| Unlocks a spinlock. More...
|
|
|
typedef atomic_flag | spinlock_t |
| The type of a spinlock, an efficient lock primitive in contended scenarios.
|
|
Easier Synchronization primitives.
This module defines synchronization primitives for the parallel runtime.
- Copyright
- Copyright (C) 2008-2022 HPDCS Group https://hpdcs.github.io
◆ spin_init
Initializes a spinlock.
- Parameters
-
lck_p | a pointer to the spinlock_t to initialize |
◆ spin_lock
#define spin_lock |
( |
|
lck_p | ) |
|
Value: __extension__({ \
while(atomic_flag_test_and_set_explicit((lck_p), memory_order_acquire)) \
spin_pause(); \
})
Locks a spinlock.
- Parameters
-
lck_p | a pointer to the spinlock_t to lock |
◆ spin_trylock
#define spin_trylock |
( |
|
lck_p | ) |
!atomic_flag_test_and_set_explicit((lck_p), memory_order_acquire) |
Executes the trylock operation on a spinlock.
- Parameters
-
lck_p | a pointer to the spinlock_t to try to lock |
- Returns
- true if the lock was acquired successfully, false otherwise
◆ spin_unlock
#define spin_unlock |
( |
|
lck_p | ) |
atomic_flag_clear_explicit((lck_p), memory_order_release) |
Unlocks a spinlock.
- Parameters
-
lck_p | a pointer to the spinlock_t to unlock |
◆ sync_thread_barrier()
bool sync_thread_barrier |
( |
void |
| ) |
|
Synchronizes threads on a barrier.
- Returns
- true if this thread has been elected as leader, false otherwise