1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
28 #include <sys/types.h>
33 /* See source file for an API description. */
35 typedef struct Barrier Barrier;
39 BARRIER_ABORTION = INT64_MAX,
41 /* bias values to store state; keep @WE < @THEY < @I */
42 BARRIER_BIAS = INT64_MIN,
43 BARRIER_WE_ABORTED = BARRIER_BIAS + 1LL,
44 BARRIER_THEY_ABORTED = BARRIER_BIAS + 2LL,
45 BARRIER_I_ABORTED = BARRIER_BIAS + 3LL,
60 int barrier_init(Barrier *obj);
61 void barrier_destroy(Barrier *b);
63 void barrier_set_role(Barrier *b, unsigned int role);
65 bool barrier_place(Barrier *b);
66 bool barrier_abort(Barrier *b);
68 bool barrier_wait_next(Barrier *b);
69 bool barrier_wait_abortion(Barrier *b);
70 bool barrier_sync_next(Barrier *b);
71 bool barrier_sync(Barrier *b);
73 static inline bool barrier_i_aborted(Barrier *b) {
74 return b->barriers == BARRIER_I_ABORTED || b->barriers == BARRIER_WE_ABORTED;
77 static inline bool barrier_they_aborted(Barrier *b) {
78 return b->barriers == BARRIER_THEY_ABORTED || b->barriers == BARRIER_WE_ABORTED;
81 static inline bool barrier_we_aborted(Barrier *b) {
82 return b->barriers == BARRIER_WE_ABORTED;
85 static inline bool barrier_is_aborted(Barrier *b) {
86 return b->barriers == BARRIER_I_ABORTED || b->barriers == BARRIER_THEY_ABORTED || b->barriers == BARRIER_WE_ABORTED;
89 static inline bool barrier_place_and_sync(Barrier *b) {
91 return barrier_sync(b);