diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-09-17 18:12:28 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-09-17 18:12:28 +0200 |
commit | 9af949cc956e647ac8ea51cf877d7fa11b97d29c (patch) | |
tree | 16f2eb256c83b3fc25241ea829ac1d9fa63bf6ca /lib/frr_pthread.c | |
parent | Merge pull request #4861 from NaveenThanikachalam/logs (diff) | |
download | frr-9af949cc956e647ac8ea51cf877d7fa11b97d29c.tar.xz frr-9af949cc956e647ac8ea51cf877d7fa11b97d29c.zip |
lib: clean up frr_pthread structs at exit
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/frr_pthread.c')
-rw-r--r-- | lib/frr_pthread.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index 97550eae5..5c71fac10 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -35,6 +35,9 @@ DEFINE_MTYPE_STATIC(LIB, PTHREAD_PRIM, "POSIX sync primitives") static void *fpt_run(void *arg); static int fpt_halt(struct frr_pthread *fpt, void **res); +/* misc sigs */ +static void frr_pthread_destroy_nolock(struct frr_pthread *fpt); + /* default frr_pthread attributes */ struct frr_pthread_attr frr_pthread_attr_default = { .start = fpt_run, @@ -59,6 +62,14 @@ void frr_pthread_finish(void) frr_pthread_stop_all(); frr_with_mutex(&frr_pthread_list_mtx) { + struct listnode *n, *nn; + struct frr_pthread *fpt; + + for (ALL_LIST_ELEMENTS(frr_pthread_list, n, nn, fpt)) { + listnode_delete(frr_pthread_list, fpt); + frr_pthread_destroy_nolock(fpt); + } + list_delete(&frr_pthread_list); } } @@ -98,12 +109,8 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr, return fpt; } -void frr_pthread_destroy(struct frr_pthread *fpt) +static void frr_pthread_destroy_nolock(struct frr_pthread *fpt) { - frr_with_mutex(&frr_pthread_list_mtx) { - listnode_delete(frr_pthread_list, fpt); - } - thread_master_free(fpt->master); pthread_mutex_destroy(&fpt->mtx); pthread_mutex_destroy(fpt->running_cond_mtx); @@ -114,6 +121,15 @@ void frr_pthread_destroy(struct frr_pthread *fpt) XFREE(MTYPE_FRR_PTHREAD, fpt); } +void frr_pthread_destroy(struct frr_pthread *fpt) +{ + frr_with_mutex(&frr_pthread_list_mtx) { + listnode_delete(frr_pthread_list, fpt); + } + + frr_pthread_destroy_nolock(fpt); +} + int frr_pthread_set_name(struct frr_pthread *fpt) { int ret = 0; |