codekingpro/portable-devtools
114k
1/*-------------------------------------------------------------------------2 *3 * barrier.h4 * Barriers for synchronizing cooperating processes.5 *6 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group7 * Portions Copyright (c) 1994, Regents of the University of California8 *9 * src/include/storage/barrier.h10 *11 *-------------------------------------------------------------------------12 */13#ifndef BARRIER_H14#define BARRIER_H15 16/*17 * For the header previously known as "barrier.h", please include18 * "port/atomics.h", which deals with atomics, compiler barriers and memory19 * barriers.20 */21 22#include "storage/condition_variable.h"23#include "storage/spin.h"24 25typedef struct Barrier26{27 slock_t mutex;28 int phase; /* phase counter */29 int participants; /* the number of participants attached */30 int arrived; /* the number of participants that have31 * arrived */32 int elected; /* highest phase elected */33 bool static_party; /* used only for assertions */34 ConditionVariable condition_variable;35} Barrier;36 37extern void BarrierInit(Barrier *barrier, int participants);38extern bool BarrierArriveAndWait(Barrier *barrier, uint32 wait_event_info);39extern bool BarrierArriveAndDetach(Barrier *barrier);40extern bool BarrierArriveAndDetachExceptLast(Barrier *barrier);41extern int BarrierAttach(Barrier *barrier);42extern bool BarrierDetach(Barrier *barrier);43extern int BarrierPhase(Barrier *barrier);44extern int BarrierParticipants(Barrier *barrier);45 46#endif /* BARRIER_H */47 