The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
sync.c
Go to the documentation of this file.
1 
11 #include <core/sync.h>
12 
13 #include <core/core.h>
14 
20 {
21  static _Thread_local unsigned phase;
22  static atomic_uint cs[2];
23  atomic_uint *c = cs + (phase & 1U);
24 
25  bool l;
26  unsigned r;
27  if (phase & 2U) {
28  l = atomic_fetch_add_explicit(c, -1, memory_order_release) == 1;
29  do {
30  r = atomic_load_explicit(c, memory_order_relaxed);
31  } while(r);
32  } else {
33  l = !atomic_fetch_add_explicit(c, 1, memory_order_release);
34  rid_t thr_cnt = n_threads;
35  do {
36  r = atomic_load_explicit(c, memory_order_relaxed);
37  } while(r != thr_cnt);
38  }
39 
40  phase = (phase + 1) & 3U;
41  return l;
42 }
rid_t
unsigned rid_t
Used to identify in a node the computing resources (threads at the moment)
Definition: core.h:77
sync.h
Easier Synchronization primitives.
n_threads
rid_t n_threads
The total number of MPI nodes in the simulation.
Definition: core.c:15
sync_thread_barrier
bool sync_thread_barrier(void)
Synchronizes threads on a barrier.
Definition: sync.c:19
core.h
Core ROOT-Sim functionalities.