summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_io.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2018-01-10 17:20:09 +0100
committerQuentin Young <qlyoung@cumulusnetworks.com>2018-01-10 17:20:09 +0100
commitf42ebe8a6750ba86d7a0550bfa6d11c446315b5a (patch)
tree79cb4a467cd1e7152b09255645e073817a358e2c /bgpd/bgp_io.c
parentbgpd: improve bgp thread startup characteristics (diff)
downloadfrr-f42ebe8a6750ba86d7a0550bfa6d11c446315b5a.tar.xz
frr-f42ebe8a6750ba86d7a0550bfa6d11c446315b5a.zip
bgpd: move startup sync lock around
Condition needs to be set inside critical section, otherwise i/o thread can deadlock. Also unlock mutex once finished with it, no need to hold the lock for the life of the program. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'bgpd/bgp_io.c')
-rw-r--r--bgpd/bgp_io.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c
index c9662e212..6861b0ee2 100644
--- a/bgpd/bgp_io.c
+++ b/bgpd/bgp_io.c
@@ -78,6 +78,7 @@ void bgp_io_init()
pthread_mutex_init(running_cond_mtx, NULL);
pthread_cond_init(running_cond, NULL);
+ /* unlocked in bgp_io_wait_running() */
pthread_mutex_lock(running_cond_mtx);
}
@@ -96,9 +97,9 @@ void *bgp_io_start(void *arg)
struct thread task;
- bgp_io_thread_run = true;
pthread_mutex_lock(running_cond_mtx);
{
+ bgp_io_thread_run = true;
pthread_cond_signal(running_cond);
}
pthread_mutex_unlock(running_cond_mtx);
@@ -119,6 +120,9 @@ void bgp_io_wait_running()
{
while (!bgp_io_thread_run)
pthread_cond_wait(running_cond, running_cond_mtx);
+
+ /* locked in bgp_io_init() */
+ pthread_mutex_unlock(running_cond_mtx);
}
int bgp_io_stop(void **result, struct frr_pthread *fpt)
@@ -126,7 +130,6 @@ int bgp_io_stop(void **result, struct frr_pthread *fpt)
thread_add_event(fpt->master, &bgp_io_finish, NULL, 0, NULL);
pthread_join(fpt->thread, result);
- pthread_mutex_unlock(running_cond_mtx);
pthread_mutex_destroy(running_cond_mtx);
pthread_cond_destroy(running_cond);