summaryrefslogtreecommitdiff
path: root/src/lib/notifier.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-09-19 17:47:26 +0200
committerdimitri staessens <[email protected]>2017-09-19 18:46:13 +0200
commit1dcef3957393c0500b81d93ffacf573e78be9a51 (patch)
treecf29abf695c1d53251560433441c29af57333e4b /src/lib/notifier.c
parent115431af51795dfd583e24a051a7749c58a900b3 (diff)
downloadouroboros-1dcef3957393c0500b81d93ffacf573e78be9a51.tar.gz
ouroboros-1dcef3957393c0500b81d93ffacf573e78be9a51.zip
ipcpd: Enroll DHT when creating dt connection
The DHT will now enroll or sync when a data transfer connection is added. This avoids the need to create a temporary data transfer connection during enrollment (and speeds it up considerably). The notifier system was modified to take an opaque pointer to the object that registers as a parameter.
Diffstat (limited to 'src/lib/notifier.c')
-rw-r--r--src/lib/notifier.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/notifier.c b/src/lib/notifier.c
index cfd383d4..5c38cf58 100644
--- a/src/lib/notifier.c
+++ b/src/lib/notifier.c
@@ -30,6 +30,7 @@
struct listener {
struct list_head next;
notifier_fn_t callback;
+ void * obj;
};
struct {
@@ -72,13 +73,16 @@ void notifier_event(int event,
pthread_mutex_lock(&notifier.lock);
- list_for_each(p, &notifier.listeners)
- list_entry(p, struct listener, next)->callback(event, o);
+ list_for_each(p, &notifier.listeners) {
+ struct listener * l = list_entry(p, struct listener, next);
+ l->callback(l->obj, event, o);
+ }
pthread_mutex_unlock(&notifier.lock);
}
-int notifier_reg(notifier_fn_t callback)
+int notifier_reg(notifier_fn_t callback,
+ void * obj)
{
struct listener * l;
struct list_head * p;
@@ -100,8 +104,9 @@ int notifier_reg(notifier_fn_t callback)
}
l->callback = callback;
+ l->obj = obj;
- list_add(&l->next, &notifier.listeners);
+ list_add_tail(&l->next, &notifier.listeners);
pthread_mutex_unlock(&notifier.lock);