threads/mutex: Ensure mutex held before signaling

Ensure that the mutex protecting the condition variable is held before
signaling it. This ensures that the thread(s) awaiting the signal are
notified.

Issue: 6569
pull/10413/head
Jeff Lucovsky 1 year ago committed by Victor Julien
parent e891ef3d4e
commit 2a1a70b308

@ -1239,13 +1239,17 @@ static int TmThreadKillThread(ThreadVars *tv)
}
if (tv->inq != NULL) {
for (int i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) {
SCMutexLock(&tv->inq->pq->mutex_q);
SCCondSignal(&tv->inq->pq->cond_q);
SCMutexUnlock(&tv->inq->pq->mutex_q);
}
SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id);
}
if (tv->ctrl_cond != NULL ) {
SCCtrlMutexLock(tv->ctrl_mutex);
pthread_cond_broadcast(tv->ctrl_cond);
SCCtrlMutexUnlock(tv->ctrl_mutex);
}
return 0;
}
@ -1425,7 +1429,9 @@ again:
if (tv->inq != NULL) {
for (int i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) {
SCMutexLock(&tv->inq->pq->mutex_q);
SCCondSignal(&tv->inq->pq->cond_q);
SCMutexUnlock(&tv->inq->pq->mutex_q);
}
SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id);
}
@ -1505,7 +1511,9 @@ again:
* THV_KILL flag. */
if (tv->inq != NULL) {
for (int i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) {
SCMutexLock(&tv->inq->pq->mutex_q);
SCCondSignal(&tv->inq->pq->cond_q);
SCMutexUnlock(&tv->inq->pq->mutex_q);
}
SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id);
}
@ -2296,7 +2304,9 @@ void TmThreadsInjectFlowById(Flow *f, const int id)
/* wake up listening thread(s) if necessary */
if (tv->inq != NULL) {
SCMutexLock(&tv->inq->pq->mutex_q);
SCCondSignal(&tv->inq->pq->cond_q);
SCMutexUnlock(&tv->inq->pq->mutex_q);
} else if (tv->break_loop) {
TmThreadsCaptureBreakLoop(tv);
}

@ -76,8 +76,11 @@ void TmqhInputSimpleShutdownHandler(ThreadVars *tv)
return;
}
for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++)
for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) {
SCMutexLock(&tv->inq->pq->mutex_q);
SCCondSignal(&tv->inq->pq->cond_q);
SCMutexUnlock(&tv->inq->pq->mutex_q);
}
}
void TmqhOutputSimple(ThreadVars *t, Packet *p)

Loading…
Cancel
Save