diff options
author | Andres Freund <andres@anarazel.de> | 2017-11-29 17:07:16 -0800 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2017-11-29 17:07:16 -0800 |
commit | 1145acc70debacc34de01fac238defde543f4ed4 (patch) | |
tree | 9fa97305a0fb9a7ccb91a2d086c37a2f3ec33c9c /src/include | |
parent | fa330f9adf4e83c0707b0b1164e7bf09c9204b3d (diff) | |
download | postgresql-1145acc70debacc34de01fac238defde543f4ed4.tar.gz postgresql-1145acc70debacc34de01fac238defde543f4ed4.zip |
Add a barrier primitive for synchronizing backends.
Provide support for dynamic or static parties of processes to wait for
all processes to reach point in the code before continuing.
This is similar to the mechanism of the same name in POSIX threads and
MPI, though has explicit phasing and dynamic party support like the
Java core library's Phaser.
This will be used by an upcoming patch adding support for parallel
hash joins.
Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=2_y7oi01OjA_wLvYcWMc9_d=LaoxrY3eiROCZkB_qakA@mail.gmail.com
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/storage/barrier.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/include/storage/barrier.h b/src/include/storage/barrier.h new file mode 100644 index 00000000000..0abaa2b98b7 --- /dev/null +++ b/src/include/storage/barrier.h @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + * + * barrier.h + * Barriers for synchronizing cooperating processes. + * + * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/barrier.h + * + *------------------------------------------------------------------------- + */ +#ifndef BARRIER_H +#define BARRIER_H + +/* + * For the header previously known as "barrier.h", please include + * "port/atomics.h", which deals with atomics, compiler barriers and memory + * barriers. + */ + +#include "storage/condition_variable.h" +#include "storage/spin.h" + +typedef struct Barrier +{ + slock_t mutex; + int phase; /* phase counter */ + int participants; /* the number of participants attached */ + int arrived; /* the number of participants that have + * arrived */ + int elected; /* highest phase elected */ + bool static_party; /* used only for assertions */ + ConditionVariable condition_variable; +} Barrier; + +extern void BarrierInit(Barrier *barrier, int num_workers); +extern bool BarrierArriveAndWait(Barrier *barrier, uint32 wait_event_info); +extern bool BarrierArriveAndDetach(Barrier *barrier); +extern int BarrierAttach(Barrier *barrier); +extern bool BarrierDetach(Barrier *barrier); +extern int BarrierPhase(Barrier *barrier); +extern int BarrierParticipants(Barrier *barrier); + +#endif /* BARRIER_H */ |