diff --git a/src/counters.c b/src/counters.c index 197fe79ec6..6840fa9ea8 100644 --- a/src/counters.c +++ b/src/counters.c @@ -306,6 +306,8 @@ static void *SCPerfMgmtThread(void *arg) cond_time.tv_sec = time(NULL) + sc_counter_tts; cond_time.tv_nsec = 0; + /* wait for the set time, or until we are woken up by + * the shutdown procedure */ SCCtrlMutexLock(tv_local->ctrl_mutex); SCCtrlCondTimedwait(tv_local->ctrl_cond, tv_local->ctrl_mutex, &cond_time); SCCtrlMutexUnlock(tv_local->ctrl_mutex); @@ -380,6 +382,8 @@ static void *SCPerfWakeupThread(void *arg) cond_time.tv_sec = time(NULL) + SC_PERF_WUT_TTS; cond_time.tv_nsec = 0; + /* wait for the set time, or until we are woken up by + * the shutdown procedure */ SCCtrlMutexLock(tv_local->ctrl_mutex); SCCtrlCondTimedwait(tv_local->ctrl_cond, tv_local->ctrl_mutex, &cond_time); SCCtrlMutexUnlock(tv_local->ctrl_mutex); @@ -828,6 +832,9 @@ void SCPerfInitCounterApi(void) /** * \brief Spawns the wakeup, and the management thread used by the perf * counter api + * + * The threads use the condition variable in the thread vars to control + * their wait loops to make sure the main thread can quickly kill them. */ void SCPerfSpawnThreads(void) { diff --git a/src/tm-threads.c b/src/tm-threads.c index 171aca2e48..6ad8b6fedf 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -1748,6 +1748,9 @@ void TmThreadSetAOF(ThreadVars *tv, uint8_t aof) /** * \brief Initializes the mutex and condition variables for this TV * + * It can be used by a thread to control a wait loop that can also be + * influenced by other threads. + * * \param tv Pointer to a TV instance */ void TmThreadInitMC(ThreadVars *tv) @@ -1760,19 +1763,19 @@ void TmThreadInitMC(ThreadVars *tv) if (SCCtrlMutexInit(tv->ctrl_mutex, NULL) != 0) { printf("Error initializing the tv->m mutex\n"); - exit(0); + exit(EXIT_FAILURE); } if ( (tv->ctrl_cond = SCMalloc(sizeof(*tv->ctrl_cond))) == NULL) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in TmThreadInitMC. " "Exiting..."); - exit(0); + exit(EXIT_FAILURE); } if (SCCtrlCondInit(tv->ctrl_cond, NULL) != 0) { SCLogError(SC_ERR_FATAL, "Error initializing the tv->cond condition " "variable"); - exit(0); + exit(EXIT_FAILURE); } return;