[PATCH] lib: Add cleanup function in notifier

  • From: Sander Vrijders <sander.vrijders@xxxxxxxx>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Thu, 11 Oct 2018 15:56:24 +0200

This adds a cleanup function in the notifier in case it gets
cancelled, which is a possibility in some callbacks.

Signed-off-by: Sander Vrijders <sander.vrijders@xxxxxxxx>
---
 src/lib/notifier.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/lib/notifier.c b/src/lib/notifier.c
index 593a0e7..4f77f2e 100644
--- a/src/lib/notifier.c
+++ b/src/lib/notifier.c
@@ -75,12 +75,15 @@ void notifier_event(int          event,
 
         pthread_rwlock_rdlock(&notifier.lock);
 
+        pthread_cleanup_push((void (*) (void *)) pthread_rwlock_unlock,
+                             (void *) &notifier.lock)
+
         list_for_each(p, &notifier.listeners) {
                 struct listener * l = list_entry(p, struct listener, next);
                 l->callback(l->obj, event, o);
         }
 
-        pthread_rwlock_unlock(&notifier.lock);
+        pthread_cleanup_pop(true);
 }
 
 int notifier_reg(notifier_fn_t callback,
-- 
2.19.1


Other related posts:

  • » [PATCH] lib: Add cleanup function in notifier - Sander Vrijders