summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shared/barrier.c19
-rw-r--r--src/shared/barrier.h2
2 files changed, 16 insertions, 5 deletions
diff --git a/src/shared/barrier.c b/src/shared/barrier.c
index 4a5544de27..f65363a67b 100644
--- a/src/shared/barrier.c
+++ b/src/shared/barrier.c
@@ -112,15 +112,24 @@
* Returns: 0 on success, negative error code on failure.
*/
int barrier_create(Barrier *b) {
+ _cleanup_(barrier_destroyp) Barrier *staging = b;
+ int r;
+
assert(b);
- if ((b->me = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) < 0 ||
- (b->them = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) < 0 ||
- pipe2(b->pipe, O_CLOEXEC | O_NONBLOCK) < 0) {
- barrier_destroy(b);
+ b->me = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
+ if (b->me < 0)
+ return -errno;
+
+ b->them = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
+ if (b->them < 0)
+ return -errno;
+
+ r = pipe2(b->pipe, O_CLOEXEC | O_NONBLOCK);
+ if (r < 0)
return -errno;
- }
+ staging = NULL;
return 0;
}
diff --git a/src/shared/barrier.h b/src/shared/barrier.h
index 53b4439fb2..c55e311344 100644
--- a/src/shared/barrier.h
+++ b/src/shared/barrier.h
@@ -62,6 +62,8 @@ struct Barrier {
int barrier_create(Barrier *obj);
void barrier_destroy(Barrier *b);
+DEFINE_TRIVIAL_CLEANUP_FUNC(Barrier*, barrier_destroy);
+
void barrier_set_role(Barrier *b, unsigned int role);
bool barrier_place(Barrier *b);