Lines Matching refs:b

93 int barrier_create(Barrier *b) {  in barrier_create()  argument
94 _unused_ _cleanup_(barrier_destroyp) Barrier *staging = b; in barrier_create()
97 assert(b); in barrier_create()
99 b->me = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); in barrier_create()
100 if (b->me < 0) in barrier_create()
103 b->them = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); in barrier_create()
104 if (b->them < 0) in barrier_create()
107 r = pipe2(b->pipe, O_CLOEXEC | O_NONBLOCK); in barrier_create()
127 Barrier* barrier_destroy(Barrier *b) { in barrier_destroy() argument
128 if (!b) in barrier_destroy()
131 b->me = safe_close(b->me); in barrier_destroy()
132 b->them = safe_close(b->them); in barrier_destroy()
133 safe_close_pair(b->pipe); in barrier_destroy()
134 b->barriers = 0; in barrier_destroy()
155 void barrier_set_role(Barrier *b, unsigned role) { in barrier_set_role() argument
156 assert(b); in barrier_set_role()
159 assert(b->pipe[0] >= 0 && b->pipe[1] >= 0); in barrier_set_role()
162 b->pipe[1] = safe_close(b->pipe[1]); in barrier_set_role()
164 b->pipe[0] = safe_close(b->pipe[0]); in barrier_set_role()
167 SWAP_TWO(b->me, b->them); in barrier_set_role()
172 static bool barrier_write(Barrier *b, uint64_t buf) { in barrier_write() argument
176 if (barrier_i_aborted(b)) in barrier_write()
179 assert(b->me >= 0); in barrier_write()
181 len = write(b->me, &buf, sizeof(buf)); in barrier_write()
189 if (barrier_they_aborted(b)) in barrier_write()
190 b->barriers = BARRIER_WE_ABORTED; in barrier_write()
192 b->barriers = BARRIER_I_ABORTED; in barrier_write()
193 } else if (!barrier_is_aborted(b)) in barrier_write()
194 b->barriers += buf; in barrier_write()
196 return !barrier_i_aborted(b); in barrier_write()
204 safe_close_pair(b->pipe); in barrier_write()
205 b->barriers = BARRIER_WE_ABORTED; in barrier_write()
210 static bool barrier_read(Barrier *b, int64_t comp) { in barrier_read() argument
211 if (barrier_they_aborted(b)) in barrier_read()
214 while (b->barriers > comp) { in barrier_read()
216 { .fd = b->pipe[0] >= 0 ? b->pipe[0] : b->pipe[1], in barrier_read()
218 { .fd = b->them, in barrier_read()
233 len = read(b->them, &buf, sizeof(buf)); in barrier_read()
251 if (barrier_i_aborted(b)) in barrier_read()
252 b->barriers = BARRIER_WE_ABORTED; in barrier_read()
254 b->barriers = BARRIER_THEY_ABORTED; in barrier_read()
255 } else if (!barrier_is_aborted(b)) in barrier_read()
256 b->barriers -= buf; in barrier_read()
259 return !barrier_they_aborted(b); in barrier_read()
267 safe_close_pair(b->pipe); in barrier_read()
268 b->barriers = BARRIER_WE_ABORTED; in barrier_read()
282 bool barrier_place(Barrier *b) { in barrier_place() argument
283 assert(b); in barrier_place()
285 if (barrier_is_aborted(b)) in barrier_place()
288 barrier_write(b, BARRIER_SINGLE); in barrier_place()
307 bool barrier_abort(Barrier *b) { in barrier_abort() argument
308 assert(b); in barrier_abort()
310 barrier_write(b, BARRIER_ABORTION); in barrier_abort()
311 return !barrier_they_aborted(b); in barrier_abort()
325 bool barrier_wait_next(Barrier *b) { in barrier_wait_next() argument
326 assert(b); in barrier_wait_next()
328 if (barrier_is_aborted(b)) in barrier_wait_next()
331 barrier_read(b, b->barriers - 1); in barrier_wait_next()
332 return !barrier_is_aborted(b); in barrier_wait_next()
346 bool barrier_wait_abortion(Barrier *b) { in barrier_wait_abortion() argument
347 assert(b); in barrier_wait_abortion()
349 barrier_read(b, BARRIER_THEY_ABORTED); in barrier_wait_abortion()
350 return !barrier_i_aborted(b); in barrier_wait_abortion()
366 bool barrier_sync_next(Barrier *b) { in barrier_sync_next() argument
367 assert(b); in barrier_sync_next()
369 if (barrier_is_aborted(b)) in barrier_sync_next()
372 barrier_read(b, MAX((int64_t)0, b->barriers - 1)); in barrier_sync_next()
373 return !barrier_is_aborted(b); in barrier_sync_next()
388 bool barrier_sync(Barrier *b) { in barrier_sync() argument
389 assert(b); in barrier_sync()
391 if (barrier_is_aborted(b)) in barrier_sync()
394 barrier_read(b, 0); in barrier_sync()
395 return !barrier_is_aborted(b); in barrier_sync()