summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2020-03-08 14:24:55 +0100
committerSander Vrijders <sander@ouroboros.rocks>2020-03-14 15:38:49 +0100
commit0df9186d8d6248ecc3a82094b8cac9262287c704 (patch)
treef26b6c601260290a307e7fc0208eab791776014e
parent9fac3ad2a05c9025acdad6feae3932711dbcd561 (diff)
downloadouroboros-0df9186d8d6248ecc3a82094b8cac9262287c704.tar.gz
ouroboros-0df9186d8d6248ecc3a82094b8cac9262287c704.zip
ipcpd: Fix locking in link_state policy
There were updates under rdlock instead of wrlock, causing data races and trouble. Also speeds up shutdown a bit. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
-rw-r--r--src/ipcpd/unicast/pol/link_state.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/ipcpd/unicast/pol/link_state.c b/src/ipcpd/unicast/pol/link_state.c
index 5360f556..d9482876 100644
--- a/src/ipcpd/unicast/pol/link_state.c
+++ b/src/ipcpd/unicast/pol/link_state.c
@@ -646,7 +646,7 @@ static void * lsupdate(void * o)
while (true) {
clock_gettime(CLOCK_REALTIME_COARSE, &now);
- pthread_rwlock_rdlock(&ls.db_lock);
+ pthread_rwlock_wrlock(&ls.db_lock);
pthread_cleanup_push((void (*) (void *)) pthread_rwlock_unlock,
(void *) &ls.db_lock);
@@ -1015,13 +1015,14 @@ void link_state_fini(void)
rib_unreg(LSDB);
- pthread_cancel(ls.listener);
- pthread_join(ls.listener, NULL);
+ notifier_unreg(handle_event);
+ pthread_cancel(ls.listener);
pthread_cancel(ls.lsreader);
- pthread_join(ls.lsreader, NULL);
-
pthread_cancel(ls.lsupdate);
+
+ pthread_join(ls.listener, NULL);
+ pthread_join(ls.lsreader, NULL);
pthread_join(ls.lsupdate, NULL);
fset_destroy(ls.mgmt_set);
@@ -1043,6 +1044,4 @@ void link_state_fini(void)
pthread_rwlock_destroy(&ls.db_lock);
pthread_mutex_destroy(&ls.routing_i_lock);
-
- notifier_unreg(handle_event);
}