threading: explain purpose of threadvars mucond

pull/1487/head
Victor Julien 11 years ago
parent 478719ee9d
commit fb479902e4

@ -306,6 +306,8 @@ static void *SCPerfMgmtThread(void *arg)
cond_time.tv_sec = time(NULL) + sc_counter_tts; cond_time.tv_sec = time(NULL) + sc_counter_tts;
cond_time.tv_nsec = 0; 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); SCCtrlMutexLock(tv_local->ctrl_mutex);
SCCtrlCondTimedwait(tv_local->ctrl_cond, tv_local->ctrl_mutex, &cond_time); SCCtrlCondTimedwait(tv_local->ctrl_cond, tv_local->ctrl_mutex, &cond_time);
SCCtrlMutexUnlock(tv_local->ctrl_mutex); 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_sec = time(NULL) + SC_PERF_WUT_TTS;
cond_time.tv_nsec = 0; 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); SCCtrlMutexLock(tv_local->ctrl_mutex);
SCCtrlCondTimedwait(tv_local->ctrl_cond, tv_local->ctrl_mutex, &cond_time); SCCtrlCondTimedwait(tv_local->ctrl_cond, tv_local->ctrl_mutex, &cond_time);
SCCtrlMutexUnlock(tv_local->ctrl_mutex); SCCtrlMutexUnlock(tv_local->ctrl_mutex);
@ -828,6 +832,9 @@ void SCPerfInitCounterApi(void)
/** /**
* \brief Spawns the wakeup, and the management thread used by the perf * \brief Spawns the wakeup, and the management thread used by the perf
* counter api * 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) void SCPerfSpawnThreads(void)
{ {

@ -1748,6 +1748,9 @@ void TmThreadSetAOF(ThreadVars *tv, uint8_t aof)
/** /**
* \brief Initializes the mutex and condition variables for this TV * \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 * \param tv Pointer to a TV instance
*/ */
void TmThreadInitMC(ThreadVars *tv) void TmThreadInitMC(ThreadVars *tv)
@ -1760,19 +1763,19 @@ void TmThreadInitMC(ThreadVars *tv)
if (SCCtrlMutexInit(tv->ctrl_mutex, NULL) != 0) { if (SCCtrlMutexInit(tv->ctrl_mutex, NULL) != 0) {
printf("Error initializing the tv->m mutex\n"); printf("Error initializing the tv->m mutex\n");
exit(0); exit(EXIT_FAILURE);
} }
if ( (tv->ctrl_cond = SCMalloc(sizeof(*tv->ctrl_cond))) == NULL) { if ( (tv->ctrl_cond = SCMalloc(sizeof(*tv->ctrl_cond))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in TmThreadInitMC. " SCLogError(SC_ERR_FATAL, "Fatal error encountered in TmThreadInitMC. "
"Exiting..."); "Exiting...");
exit(0); exit(EXIT_FAILURE);
} }
if (SCCtrlCondInit(tv->ctrl_cond, NULL) != 0) { if (SCCtrlCondInit(tv->ctrl_cond, NULL) != 0) {
SCLogError(SC_ERR_FATAL, "Error initializing the tv->cond condition " SCLogError(SC_ERR_FATAL, "Error initializing the tv->cond condition "
"variable"); "variable");
exit(0); exit(EXIT_FAILURE);
} }
return; return;

Loading…
Cancel
Save