ROOT-Sim core  3.0.0-rc.2
A General-Purpose Multi-threaded Parallel/Distributed Simulation Library
Macros | Typedefs | Functions
sync.h File Reference

Easier Synchronization primitives. More...

#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for sync.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#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...
 

Typedefs

typedef atomic_flag spinlock_t
 The type of a spinlock, an efficient lock primitive in contended scenarios.
 

Functions

bool sync_thread_barrier (void)
 Synchronizes threads on a barrier. More...
 

Detailed Description

Easier Synchronization primitives.

This module defines synchronization primitives for the parallel runtime.

Macro Definition Documentation

◆ spin_init

#define spin_init (   lck_p)    spin_unlock(lck_p)

Initializes a spinlock.

Parameters
lck_pa 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_pa 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_pa 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_pa pointer to the spinlock_t to unlock

Function Documentation

◆ 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