From f476732139917ca6400370974a56dba7226a3a79 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 30 Apr 2014 18:49:39 +0200 Subject: [PATCH] flow recycler: shutdown Only shut down when all flows in the recycle queue have been processed. --- src/flow-manager.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/flow-manager.c b/src/flow-manager.c index eb5e264e0d..a41addb1d5 100644 --- a/src/flow-manager.c +++ b/src/flow-manager.c @@ -684,6 +684,16 @@ void *FlowRecyclerThread(void *td) return NULL; } +int FlowRecyclerReadyToShutdown(void) +{ + uint32_t len = 0; + FQLOCK_LOCK(&flow_recycle_q); + len = flow_recycle_q.len; + FQLOCK_UNLOCK(&flow_recycle_q); + + return ((len == 0)); +} + /** \brief spawn the flow recycler thread */ void FlowRecyclerThreadSpawn() { @@ -712,6 +722,8 @@ void FlowRecyclerThreadSpawn() /** * \brief Used to kill flow recycler thread(s). * + * \note this should only be called when the flow manager is already gone + * * \todo Kinda hackish since it uses the tv name to identify flow recycler * thread. We need an all weather identification scheme. */ @@ -720,7 +732,11 @@ void FlowKillFlowRecyclerThread(void) ThreadVars *tv = NULL; int cnt = 0; - SCCtrlCondSignal(&flow_recycler_ctrl_cond); + /* make sure all flows are processed */ + do { + SCCtrlCondSignal(&flow_recycler_ctrl_cond); + usleep(10); + } while (FlowRecyclerReadyToShutdown() == 0); SCMutexLock(&tv_root_lock);