1 /*-------------------------------------------------------------------------
4 * Barriers for synchronizing cooperating processes.
6 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/storage/barrier.h
11 *-------------------------------------------------------------------------
17 * For the header previously known as "barrier.h", please include
18 * "port/atomics.h", which deals with atomics, compiler barriers and memory
22 #include "storage/condition_variable.h"
23 #include "storage/spin.h"
25 typedef struct Barrier
28 int phase
; /* phase counter */
29 int participants
; /* the number of participants attached */
30 int arrived
; /* the number of participants that have
32 int elected
; /* highest phase elected */
33 bool static_party
; /* used only for assertions */
34 ConditionVariable condition_variable
;
37 extern void BarrierInit(Barrier
*barrier
, int num_workers
);
38 extern bool BarrierArriveAndWait(Barrier
*barrier
, uint32 wait_event_info
);
39 extern bool BarrierArriveAndDetach(Barrier
*barrier
);
40 extern bool BarrierArriveAndDetachExceptLast(Barrier
*barrier
);
41 extern int BarrierAttach(Barrier
*barrier
);
42 extern bool BarrierDetach(Barrier
*barrier
);
43 extern int BarrierPhase(Barrier
*barrier
);
44 extern int BarrierParticipants(Barrier
*barrier
);
46 #endif /* BARRIER_H */