summaryrefslogtreecommitdiffstats
path: root/lib/qpnexus.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/qpnexus.c')
-rw-r--r--lib/qpnexus.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/qpnexus.c b/lib/qpnexus.c
index 5a5c5417..fa500e36 100644
--- a/lib/qpnexus.c
+++ b/lib/qpnexus.c
@@ -84,13 +84,18 @@ qpn_init_bgp(qpn_nexus qpn)
return qpn;
}
-/* free timers, selection, message queue and nexus */
-static void
+/* free timers, selection, message queue and nexus
+ * return NULL
+ */
+qpn_nexus
qpn_free(qpn_nexus qpn)
{
qps_file qf;
qtimer qtr;
+ if (qpn == NULL)
+ return NULL;
+
/* timers and the pile */
if (qpn->pile != NULL)
{
@@ -112,6 +117,8 @@ qpn_free(qpn_nexus qpn)
/* TODO: free qtn->queue */
XFREE(MTYPE_QPN_NEXUS, qpn) ;
+
+ return NULL;
}
/* If not main thread create new qpthread.
@@ -127,7 +134,7 @@ qpn_exec(qpn_nexus qpn)
else
{
/* create a qpthread and run the state machine in it */
- qpn->thread_id = qpt_thread_create(qpn->start, qpn, NULL) ;
+ qpt_thread_create(qpn->start, qpn, NULL) ;
}
}
@@ -173,8 +180,6 @@ qpn_start_main(void* arg)
}
}
- qpn_free(qpn);
-
return NULL;
}
@@ -224,7 +229,14 @@ qpn_start_bgp(void* arg)
mqueue_done_waiting(qpn->queue, qpn->mts);
}
- qpn_free(qpn);
-
return NULL;
}
+
+/* Ask the thread to terminate itself quickly and cleanly */
+void
+qpn_terminate(qpn_nexus qpn)
+{
+ qpn->terminate = 1;
+ /* wake up any pselect */
+ qpt_thread_signal(qpn->thread_id, SIGMQUEUE);
+}