Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7888b09

Browse files
committed
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: Thomas Munro <thomas.munro@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKG%2BA6ftXPz4oe92%2Bx8Er%2BxpGZqto70-Q_ERwRaSyA%3DafNg%40mail.gmail.com
1 parent 13b58f8 commit 7888b09

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/backend/storage/ipc/barrier.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,28 @@ BarrierArriveAndDetach(Barrier *barrier)
205205
return BarrierDetachImpl(barrier, true);
206206
}
207207

208+
/*
209+
* Arrive at a barrier, and detach all but the last to arrive. Returns true if
210+
* the caller was the last to arrive, and is therefore still attached.
211+
*/
212+
bool
213+
BarrierArriveAndDetachExceptLast(Barrier *barrier)
214+
{
215+
SpinLockAcquire(&barrier->mutex);
216+
if (barrier->participants > 1)
217+
{
218+
--barrier->participants;
219+
SpinLockRelease(&barrier->mutex);
220+
221+
return false;
222+
}
223+
Assert(barrier->participants == 1);
224+
++barrier->phase;
225+
SpinLockRelease(&barrier->mutex);
226+
227+
return true;
228+
}
229+
208230
/*
209231
* Attach to a barrier. All waiting participants will now wait for this
210232
* participant to call BarrierArriveAndWait(), BarrierDetach() or

src/include/storage/barrier.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct Barrier
3737
extern void BarrierInit(Barrier *barrier, int num_workers);
3838
extern bool BarrierArriveAndWait(Barrier *barrier, uint32 wait_event_info);
3939
extern bool BarrierArriveAndDetach(Barrier *barrier);
40+
extern bool BarrierArriveAndDetachExceptLast(Barrier *barrier);
4041
extern int BarrierAttach(Barrier *barrier);
4142
extern bool BarrierDetach(Barrier *barrier);
4243
extern int BarrierPhase(Barrier *barrier);

0 commit comments

Comments
 (0)