Commit 7888b099 authored by Thomas Munro's avatar Thomas Munro

Add BarrierArriveAndDetachExceptLast().

Provide a way for one process to continue the remaining phases of a
(previously) parallel computation alone.  Later patches will use this to
extend Parallel Hash Join.

Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: default avatarThomas Munro <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/CA%2BhUKG%2BA6ftXPz4oe92%2Bx8Er%2BxpGZqto70-Q_ERwRaSyA%3DafNg%40mail.gmail.com
parent 13b58f89
...@@ -205,6 +205,28 @@ BarrierArriveAndDetach(Barrier *barrier) ...@@ -205,6 +205,28 @@ BarrierArriveAndDetach(Barrier *barrier)
return BarrierDetachImpl(barrier, true); return BarrierDetachImpl(barrier, true);
} }
/*
* Arrive at a barrier, and detach all but the last to arrive. Returns true if
* the caller was the last to arrive, and is therefore still attached.
*/
bool
BarrierArriveAndDetachExceptLast(Barrier *barrier)
{
SpinLockAcquire(&barrier->mutex);
if (barrier->participants > 1)
{
--barrier->participants;
SpinLockRelease(&barrier->mutex);
return false;
}
Assert(barrier->participants == 1);
++barrier->phase;
SpinLockRelease(&barrier->mutex);
return true;
}
/* /*
* Attach to a barrier. All waiting participants will now wait for this * Attach to a barrier. All waiting participants will now wait for this
* participant to call BarrierArriveAndWait(), BarrierDetach() or * participant to call BarrierArriveAndWait(), BarrierDetach() or
......
...@@ -37,6 +37,7 @@ typedef struct Barrier ...@@ -37,6 +37,7 @@ typedef struct Barrier
extern void BarrierInit(Barrier *barrier, int num_workers); extern void BarrierInit(Barrier *barrier, int num_workers);
extern bool BarrierArriveAndWait(Barrier *barrier, uint32 wait_event_info); extern bool BarrierArriveAndWait(Barrier *barrier, uint32 wait_event_info);
extern bool BarrierArriveAndDetach(Barrier *barrier); extern bool BarrierArriveAndDetach(Barrier *barrier);
extern bool BarrierArriveAndDetachExceptLast(Barrier *barrier);
extern int BarrierAttach(Barrier *barrier); extern int BarrierAttach(Barrier *barrier);
extern bool BarrierDetach(Barrier *barrier); extern bool BarrierDetach(Barrier *barrier);
extern int BarrierPhase(Barrier *barrier); extern int BarrierPhase(Barrier *barrier);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment