diff options
Diffstat (limited to 'src/lib/notifier.c')
-rw-r--r-- | src/lib/notifier.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/lib/notifier.c b/src/lib/notifier.c index dd211dd3..4fccd371 100644 --- a/src/lib/notifier.c +++ b/src/lib/notifier.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Notifier event system using callbacks * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -25,8 +25,9 @@ #include <ouroboros/errno.h> #include <ouroboros/notifier.h> #include <ouroboros/list.h> +#include <ouroboros/utils.h> +#include <ouroboros/pthread.h> -#include <pthread.h> #include <stdlib.h> struct listener { @@ -75,8 +76,7 @@ void notifier_event(int event, pthread_rwlock_rdlock(¬ifier.lock); - pthread_cleanup_push((void (*) (void *)) pthread_rwlock_unlock, - (void *) ¬ifier.lock) + pthread_cleanup_push(__cleanup_rwlock_unlock, ¬ifier.lock) list_for_each(p, ¬ifier.listeners) { struct listener * l = list_entry(p, struct listener, next); @@ -95,18 +95,14 @@ int notifier_reg(notifier_fn_t callback, pthread_rwlock_wrlock(¬ifier.lock); list_for_each(p, ¬ifier.listeners) { - struct listener * l = list_entry(p, struct listener, next); - if (l->callback == callback) { - pthread_rwlock_unlock(¬ifier.lock); - return -EPERM; - } + l = list_entry(p, struct listener, next); + if (l->callback == callback) + goto fail; } l = malloc(sizeof(*l)); - if (l == NULL) { - pthread_rwlock_unlock(¬ifier.lock); - return -ENOMEM; - } + if (l == NULL) + goto fail; l->callback = callback; l->obj = obj; @@ -116,6 +112,10 @@ int notifier_reg(notifier_fn_t callback, pthread_rwlock_unlock(¬ifier.lock); return 0; + fail: + pthread_rwlock_unlock(¬ifier.lock); + return -1; + } void notifier_unreg(notifier_fn_t callback) |