summaryrefslogtreecommitdiff
path: root/src/lib/rib.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2017-03-27 11:51:53 +0200
committerSander Vrijders <[email protected]>2017-03-28 10:24:54 +0200
commit8fd39fd9e1cc65147a6f1a3fa5027c9ab2cb4a68 (patch)
treea2aeb1e66e57785e4b1393a1aefc07c6c6212065 /src/lib/rib.c
parent8f88486a5a549e1b6644670e5eb011a9309f176b (diff)
downloadouroboros-8fd39fd9e1cc65147a6f1a3fa5027c9ab2cb4a68.tar.gz
ouroboros-8fd39fd9e1cc65147a6f1a3fa5027c9ab2cb4a68.zip
lib: Fix list_move on wrong list
The list move was being done on the whole list of sub events, whereas it should only be done on the first entry. A cleanup handler was also added.
Diffstat (limited to 'src/lib/rib.c')
-rw-r--r--src/lib/rib.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lib/rib.c b/src/lib/rib.c
index fc58f266..d39a17d2 100644
--- a/src/lib/rib.c
+++ b/src/lib/rib.c
@@ -1114,6 +1114,7 @@ int rib_event_wait(ro_set_t * set,
{
struct rib_sub * sub;
struct timespec abstime;
+ struct revent * ev;
ssize_t ret = 0;
@@ -1136,6 +1137,9 @@ int rib_event_wait(ro_set_t * set,
pthread_mutex_lock(&sub->lock);
+ pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock,
+ (void *) &sub->lock);
+
while (list_is_empty(&sub->events) && ret != -ETIMEDOUT) {
if (timeout != NULL)
ret = -pthread_cond_timedwait(&sub->cond,
@@ -1145,12 +1149,14 @@ int rib_event_wait(ro_set_t * set,
ret = -pthread_cond_wait(&sub->cond, &sub->lock);
}
- pthread_mutex_unlock(&sub->lock);
+ pthread_cleanup_pop(true);
pthread_rwlock_wrlock(&rib.lock);
- if (ret != -ETIMEDOUT)
- list_move(&rq->events, &sub->events);
+ if (ret != -ETIMEDOUT) {
+ ev = list_first_entry(&sub->events, struct revent, next);
+ list_move(&ev->next, &rq->events);
+ }
pthread_rwlock_unlock(&rib.lock);