diff options
author | Sander Vrijders <[email protected]> | 2018-06-19 11:38:23 +0200 |
---|---|---|
committer | Dimitri Staessens <[email protected]> | 2018-06-19 13:55:45 +0200 |
commit | a5362f24b4dd48f7203be418c6d66f6edccb8d69 (patch) | |
tree | d74819582ddf4e4ccfe629dd1b8d2d96df841aab /src/lib/notifier.c | |
parent | aea32291530c2dbec84ff424a8c7f224bd1b13d7 (diff) | |
download | ouroboros-a5362f24b4dd48f7203be418c6d66f6edccb8d69.tar.gz ouroboros-a5362f24b4dd48f7203be418c6d66f6edccb8d69.zip |
ipcpd: Change connection down to flow down
The DT component was flagging a connection as down and passing the fd
that was down. Of course the other components expect a connection
instead of just a fd. Now the connection manager will listen to flow
up and down events, and flag the connection up or down if needed.
Signed-off-by: Sander Vrijders <[email protected]>
Signed-off-by: Dimitri Staessens <[email protected]>
Diffstat (limited to 'src/lib/notifier.c')
-rw-r--r-- | src/lib/notifier.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/lib/notifier.c b/src/lib/notifier.c index 2c098f6f..593a0e70 100644 --- a/src/lib/notifier.c +++ b/src/lib/notifier.c @@ -20,6 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ +#define _POSIX_C_SOURCE 200112L + #include <ouroboros/errno.h> #include <ouroboros/notifier.h> #include <ouroboros/list.h> @@ -35,12 +37,12 @@ struct listener { struct { struct list_head listeners; - pthread_mutex_t lock; + pthread_rwlock_t lock; } notifier; int notifier_init(void) { - if (pthread_mutex_init(¬ifier.lock, NULL)) + if (pthread_rwlock_init(¬ifier.lock, NULL)) return -1; list_head_init(¬ifier.listeners); @@ -53,7 +55,7 @@ void notifier_fini(void) struct list_head * p; struct list_head * h; - pthread_mutex_lock(¬ifier.lock); + pthread_rwlock_wrlock(¬ifier.lock); list_for_each_safe(p, h, ¬ifier.listeners) { struct listener * l = list_entry(p, struct listener, next); @@ -61,9 +63,9 @@ void notifier_fini(void) free(l); } - pthread_mutex_unlock(¬ifier.lock); + pthread_rwlock_unlock(¬ifier.lock); - pthread_mutex_destroy(¬ifier.lock); + pthread_rwlock_destroy(¬ifier.lock); } void notifier_event(int event, @@ -71,14 +73,14 @@ void notifier_event(int event, { struct list_head * p; - pthread_mutex_lock(¬ifier.lock); + pthread_rwlock_rdlock(¬ifier.lock); list_for_each(p, ¬ifier.listeners) { struct listener * l = list_entry(p, struct listener, next); l->callback(l->obj, event, o); } - pthread_mutex_unlock(¬ifier.lock); + pthread_rwlock_unlock(¬ifier.lock); } int notifier_reg(notifier_fn_t callback, @@ -87,19 +89,19 @@ int notifier_reg(notifier_fn_t callback, struct listener * l; struct list_head * p; - pthread_mutex_lock(¬ifier.lock); + 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_mutex_unlock(¬ifier.lock); + pthread_rwlock_unlock(¬ifier.lock); return -EPERM; } } l = malloc(sizeof(*l)); if (l == NULL) { - pthread_mutex_unlock(¬ifier.lock); + pthread_rwlock_unlock(¬ifier.lock); return -ENOMEM; } @@ -108,7 +110,7 @@ int notifier_reg(notifier_fn_t callback, list_add_tail(&l->next, ¬ifier.listeners); - pthread_mutex_unlock(¬ifier.lock); + pthread_rwlock_unlock(¬ifier.lock); return 0; } @@ -118,7 +120,7 @@ void notifier_unreg(notifier_fn_t callback) struct list_head * p; struct list_head * h; - pthread_mutex_lock(¬ifier.lock); + pthread_rwlock_wrlock(¬ifier.lock); list_for_each_safe(p, h, ¬ifier.listeners) { struct listener * l = list_entry(p, struct listener, next); @@ -129,5 +131,5 @@ void notifier_unreg(notifier_fn_t callback) } } - pthread_mutex_unlock(¬ifier.lock); + pthread_rwlock_unlock(¬ifier.lock); } |