]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: clean up frr_pthread structs at exit
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 17 Sep 2019 16:12:28 +0000 (16:12 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 17 Sep 2019 16:12:28 +0000 (16:12 +0000)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/frr_pthread.c

index 97550eae533d79827335d86489d7b9137ef31ccb..5c71fac10a332deb52f1cfa3cb4a09d4d983801a 100644 (file)
@@ -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;