File tree 2 files changed +23
-0
lines changed 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,28 @@ BarrierArriveAndDetach(Barrier *barrier)
205
205
return BarrierDetachImpl (barrier , true);
206
206
}
207
207
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
+
208
230
/*
209
231
* Attach to a barrier. All waiting participants will now wait for this
210
232
* participant to call BarrierArriveAndWait(), BarrierDetach() or
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ typedef struct Barrier
37
37
extern void BarrierInit (Barrier * barrier , int num_workers );
38
38
extern bool BarrierArriveAndWait (Barrier * barrier , uint32 wait_event_info );
39
39
extern bool BarrierArriveAndDetach (Barrier * barrier );
40
+ extern bool BarrierArriveAndDetachExceptLast (Barrier * barrier );
40
41
extern int BarrierAttach (Barrier * barrier );
41
42
extern bool BarrierDetach (Barrier * barrier );
42
43
extern int BarrierPhase (Barrier * barrier );
You can’t perform that action at this time.
0 commit comments