]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/barrier.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 /* See source file for an API description. */
12 typedef struct Barrier Barrier
;
16 BARRIER_ABORTION
= INT64_MAX
,
18 /* bias values to store state; keep @WE < @THEY < @I */
19 BARRIER_BIAS
= INT64_MIN
,
20 BARRIER_WE_ABORTED
= BARRIER_BIAS
+ 1LL,
21 BARRIER_THEY_ABORTED
= BARRIER_BIAS
+ 2LL,
22 BARRIER_I_ABORTED
= BARRIER_BIAS
+ 3LL,
37 #define BARRIER_NULL {-1, -1, {-1, -1}, 0}
39 int barrier_create(Barrier
*obj
);
40 void barrier_destroy(Barrier
*b
);
42 DEFINE_TRIVIAL_CLEANUP_FUNC(Barrier
*, barrier_destroy
);
44 void barrier_set_role(Barrier
*b
, unsigned role
);
46 bool barrier_place(Barrier
*b
);
47 bool barrier_abort(Barrier
*b
);
49 bool barrier_wait_next(Barrier
*b
);
50 bool barrier_wait_abortion(Barrier
*b
);
51 bool barrier_sync_next(Barrier
*b
);
52 bool barrier_sync(Barrier
*b
);
54 static inline bool barrier_i_aborted(Barrier
*b
) {
55 return IN_SET(b
->barriers
, BARRIER_I_ABORTED
, BARRIER_WE_ABORTED
);
58 static inline bool barrier_they_aborted(Barrier
*b
) {
59 return IN_SET(b
->barriers
, BARRIER_THEY_ABORTED
, BARRIER_WE_ABORTED
);
62 static inline bool barrier_we_aborted(Barrier
*b
) {
63 return b
->barriers
== BARRIER_WE_ABORTED
;
66 static inline bool barrier_is_aborted(Barrier
*b
) {
67 return IN_SET(b
->barriers
,
68 BARRIER_I_ABORTED
, BARRIER_THEY_ABORTED
, BARRIER_WE_ABORTED
);
71 static inline bool barrier_place_and_sync(Barrier
*b
) {
72 (void) barrier_place(b
);
73 return barrier_sync(b
);