flow: fix condition signalling

Signal threads while holding lock. This should make the signalling
more reliable.

From PTHREAD_COND(3):

"Unlocking the mutex and suspending on the condition variable is done
 atomically. Thus, if all threads always acquire the mutex before
 signaling the condition, this guarantees that the condition cannot be
 signaled (and thus ignored) between the time a thread locks the
 mutex and the time it waits on the condition variable."

Ticket: #6569.
pull/9882/head
Victor Julien 2 years ago committed by Victor Julien
parent 487b78fb3d
commit 3107a4953d

@ -84,10 +84,24 @@ SC_ATOMIC_DECLARE(uint32_t, flowrec_cnt);
SC_ATOMIC_DECLARE(uint32_t, flowrec_busy);
SC_ATOMIC_EXTERN(unsigned int, flow_flags);
SCCtrlCondT flow_manager_ctrl_cond;
SCCtrlMutex flow_manager_ctrl_mutex;
SCCtrlCondT flow_recycler_ctrl_cond;
SCCtrlMutex flow_recycler_ctrl_mutex;
static SCCtrlCondT flow_manager_ctrl_cond = PTHREAD_COND_INITIALIZER;
static SCCtrlMutex flow_manager_ctrl_mutex = PTHREAD_MUTEX_INITIALIZER;
static SCCtrlCondT flow_recycler_ctrl_cond = PTHREAD_COND_INITIALIZER;
static SCCtrlMutex flow_recycler_ctrl_mutex = PTHREAD_MUTEX_INITIALIZER;
void FlowWakeupFlowManagerThread(void)
{
SCCtrlMutexLock(&flow_manager_ctrl_mutex);
SCCtrlCondSignal(&flow_manager_ctrl_cond);
SCCtrlMutexUnlock(&flow_manager_ctrl_mutex);
}
void FlowWakeupFlowRecyclerThread(void)
{
SCCtrlMutexLock(&flow_recycler_ctrl_mutex);
SCCtrlCondSignal(&flow_recycler_ctrl_cond);
SCCtrlMutexUnlock(&flow_recycler_ctrl_mutex);
}
void FlowTimeoutsInit(void)
{
@ -942,9 +956,6 @@ void FlowManagerThreadSpawn(void)
}
flowmgr_number = (uint32_t)setting;
SCCtrlCondInit(&flow_manager_ctrl_cond, NULL);
SCCtrlMutexInit(&flow_manager_ctrl_mutex, NULL);
SCLogConfig("using %u flow manager threads", flowmgr_number);
StatsRegisterGlobalCounter("flow.memuse", FlowGetMemuse);
@ -1148,9 +1159,6 @@ void FlowRecyclerThreadSpawn(void)
}
flowrec_number = (uint32_t)setting;
SCCtrlCondInit(&flow_recycler_ctrl_cond, NULL);
SCCtrlMutexInit(&flow_recycler_ctrl_mutex, NULL);
SCLogConfig("using %u flow recycler threads", flowrec_number);
for (uint32_t u = 0; u < flowrec_number; u++) {

@ -24,13 +24,8 @@
#ifndef __FLOW_MANAGER_H__
#define __FLOW_MANAGER_H__
/** flow manager scheduling condition */
extern SCCtrlCondT flow_manager_ctrl_cond;
extern SCCtrlMutex flow_manager_ctrl_mutex;
#define FlowWakeupFlowManagerThread() SCCtrlCondSignal(&flow_manager_ctrl_cond)
extern SCCtrlCondT flow_recycler_ctrl_cond;
extern SCCtrlMutex flow_recycler_ctrl_mutex;
#define FlowWakeupFlowRecyclerThread() SCCtrlCondSignal(&flow_recycler_ctrl_cond)
void FlowWakeupFlowManagerThread(void);
void FlowWakeupFlowRecyclerThread(void);
#define FlowTimeoutsReset() FlowTimeoutsInit()
void FlowTimeoutsInit(void);

Loading…
Cancel
Save