threading: minor code style cleanups

pull/4531/head
Victor Julien 6 years ago
parent b1056b3836
commit 9d8ea3b4fe

@ -115,14 +115,11 @@ void TmThreadsUnsetFlag(ThreadVars *tv, uint16_t flag)
TmEcode TmThreadsSlotVarRun(ThreadVars *tv, Packet *p, TmEcode TmThreadsSlotVarRun(ThreadVars *tv, Packet *p,
TmSlot *slot) TmSlot *slot)
{ {
TmEcode r; for (TmSlot *s = slot; s != NULL; s = s->slot_next) {
TmSlot *s;
Packet *extra_p;
for (s = slot; s != NULL; s = s->slot_next) {
TmSlotFunc SlotFunc = SC_ATOMIC_GET(s->SlotFunc); TmSlotFunc SlotFunc = SC_ATOMIC_GET(s->SlotFunc);
PACKET_PROFILING_TMM_START(p, s->tm_id); PACKET_PROFILING_TMM_START(p, s->tm_id);
TmEcode r;
if (unlikely(s->id == 0)) { if (unlikely(s->id == 0)) {
r = SlotFunc(tv, p, SC_ATOMIC_GET(s->slot_data), &s->slot_pre_pq, &s->slot_post_pq); r = SlotFunc(tv, p, SC_ATOMIC_GET(s->slot_data), &s->slot_pre_pq, &s->slot_post_pq);
} else { } else {
@ -146,7 +143,7 @@ TmEcode TmThreadsSlotVarRun(ThreadVars *tv, Packet *p,
/* handle new packets */ /* handle new packets */
while (s->slot_pre_pq.top != NULL) { while (s->slot_pre_pq.top != NULL) {
extra_p = PacketDequeue(&s->slot_pre_pq); Packet *extra_p = PacketDequeue(&s->slot_pre_pq);
if (unlikely(extra_p == NULL)) if (unlikely(extra_p == NULL))
continue; continue;
@ -1461,8 +1458,6 @@ static bool ThreadStillHasPackets(ThreadVars *tv)
*/ */
static int TmThreadKillThread(ThreadVars *tv) static int TmThreadKillThread(ThreadVars *tv)
{ {
int i = 0;
BUG_ON(tv == NULL); BUG_ON(tv == NULL);
/* kill only once :) */ /* kill only once :) */
@ -1481,7 +1476,7 @@ static int TmThreadKillThread(ThreadVars *tv)
tv->InShutdownHandler(tv); tv->InShutdownHandler(tv);
} }
if (tv->inq != NULL) { if (tv->inq != NULL) {
for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) { for (int i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) {
SCCondSignal(&trans_q[tv->inq->id].cond_q); SCCondSignal(&trans_q[tv->inq->id].cond_q);
} }
SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id); SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id);
@ -1618,8 +1613,7 @@ again:
TmThreadsSetFlag(tv, THV_KILL_PKTACQ); TmThreadsSetFlag(tv, THV_KILL_PKTACQ);
if (tv->inq != NULL) { if (tv->inq != NULL) {
int i; for (int 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++) {
SCCondSignal(&trans_q[tv->inq->id].cond_q); SCCondSignal(&trans_q[tv->inq->id].cond_q);
} }
SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id); SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id);
@ -1699,8 +1693,7 @@ again:
TmThreadsSetFlag(tv, THV_KILL); TmThreadsSetFlag(tv, THV_KILL);
if (tv->inq != NULL) { if (tv->inq != NULL) {
int i; for (int 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++) {
SCCondSignal(&trans_q[tv->inq->id].cond_q); SCCondSignal(&trans_q[tv->inq->id].cond_q);
} }
SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id); SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id);
@ -2011,19 +2004,15 @@ void TmThreadContinue(ThreadVars *tv)
*/ */
void TmThreadContinueThreads() void TmThreadContinueThreads()
{ {
ThreadVars *tv = NULL;
int i = 0;
SCMutexLock(&tv_root_lock); SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) { for (int i = 0; i < TVT_MAX; i++) {
tv = tv_root[i]; ThreadVars *tv = tv_root[i];
while (tv != NULL) { while (tv != NULL) {
TmThreadContinue(tv); TmThreadContinue(tv);
tv = tv->next; tv = tv->next;
} }
} }
SCMutexUnlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
return; return;
} }
@ -2035,7 +2024,6 @@ void TmThreadContinueThreads()
void TmThreadPause(ThreadVars *tv) void TmThreadPause(ThreadVars *tv)
{ {
TmThreadsSetFlag(tv, THV_PAUSE); TmThreadsSetFlag(tv, THV_PAUSE);
return; return;
} }
@ -2044,22 +2032,17 @@ void TmThreadPause(ThreadVars *tv)
*/ */
void TmThreadPauseThreads() void TmThreadPauseThreads()
{ {
ThreadVars *tv = NULL;
int i = 0;
TmThreadsListThreads(); TmThreadsListThreads();
SCMutexLock(&tv_root_lock); SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) { for (int i = 0; i < TVT_MAX; i++) {
tv = tv_root[i]; ThreadVars *tv = tv_root[i];
while (tv != NULL) { while (tv != NULL) {
TmThreadPause(tv); TmThreadPause(tv);
tv = tv->next; tv = tv->next;
} }
} }
SCMutexUnlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
return;
} }
/** /**
@ -2067,13 +2050,9 @@ void TmThreadPauseThreads()
*/ */
void TmThreadCheckThreadState(void) void TmThreadCheckThreadState(void)
{ {
ThreadVars *tv = NULL;
int i = 0;
SCMutexLock(&tv_root_lock); SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) { for (int i = 0; i < TVT_MAX; i++) {
tv = tv_root[i]; ThreadVars *tv = tv_root[i];
while (tv) { while (tv) {
if (TmThreadsCheckFlag(tv, THV_FAILED)) { if (TmThreadsCheckFlag(tv, THV_FAILED)) {
FatalError(SC_ERR_FATAL, "thread %s failed", tv->name); FatalError(SC_ERR_FATAL, "thread %s failed", tv->name);
@ -2095,8 +2074,6 @@ void TmThreadCheckThreadState(void)
*/ */
TmEcode TmThreadWaitOnThreadInit(void) TmEcode TmThreadWaitOnThreadInit(void)
{ {
ThreadVars *tv = NULL;
int i = 0;
uint16_t mgt_num = 0; uint16_t mgt_num = 0;
uint16_t ppt_num = 0; uint16_t ppt_num = 0;
@ -2106,8 +2083,8 @@ TmEcode TmThreadWaitOnThreadInit(void)
again: again:
SCMutexLock(&tv_root_lock); SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) { for (int i = 0; i < TVT_MAX; i++) {
tv = tv_root[i]; ThreadVars *tv = tv_root[i];
while (tv != NULL) { while (tv != NULL) {
if (TmThreadsCheckFlag(tv, (THV_CLOSED|THV_DEAD))) { if (TmThreadsCheckFlag(tv, (THV_CLOSED|THV_DEAD))) {
SCMutexUnlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
@ -2173,13 +2150,10 @@ again:
ThreadVars *TmThreadsGetCallingThread(void) ThreadVars *TmThreadsGetCallingThread(void)
{ {
pthread_t self = pthread_self(); pthread_t self = pthread_self();
ThreadVars *tv = NULL;
int i = 0;
SCMutexLock(&tv_root_lock); SCMutexLock(&tv_root_lock);
for (int i = 0; i < TVT_MAX; i++) {
for (i = 0; i < TVT_MAX; i++) { ThreadVars *tv = tv_root[i];
tv = tv_root[i];
while (tv) { while (tv) {
if (pthread_equal(self, tv->t)) { if (pthread_equal(self, tv->t)) {
SCMutexUnlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
@ -2188,9 +2162,7 @@ ThreadVars *TmThreadsGetCallingThread(void)
tv = tv->next; tv = tv->next;
} }
} }
SCMutexUnlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
return NULL; return NULL;
} }
@ -2199,13 +2171,10 @@ ThreadVars *TmThreadsGetCallingThread(void)
*/ */
uint32_t TmThreadCountThreadsByTmmFlags(uint8_t flags) uint32_t TmThreadCountThreadsByTmmFlags(uint8_t flags)
{ {
ThreadVars *tv = NULL;
int i = 0;
uint32_t cnt = 0; uint32_t cnt = 0;
SCMutexLock(&tv_root_lock); SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) { for (int i = 0; i < TVT_MAX; i++) {
tv = tv_root[i]; ThreadVars *tv = tv_root[i];
while (tv != NULL) { while (tv != NULL) {
if ((tv->tmm_flags & flags) == flags) if ((tv->tmm_flags & flags) == flags)
cnt++; cnt++;
@ -2277,13 +2246,9 @@ static SCMutex thread_store_lock = SCMUTEX_INITIALIZER;
void TmThreadsListThreads(void) void TmThreadsListThreads(void)
{ {
Thread *t;
size_t s;
SCMutexLock(&thread_store_lock); SCMutexLock(&thread_store_lock);
for (size_t s = 0; s < thread_store.threads_size; s++) {
for (s = 0; s < thread_store.threads_size; s++) { Thread *t = &thread_store.threads[s];
t = &thread_store.threads[s];
if (t == NULL || t->in_use == 0) if (t == NULL || t->in_use == 0)
continue; continue;
@ -2296,7 +2261,6 @@ void TmThreadsListThreads(void)
tv, tv->type, tv->name, tv->tmm_flags, flags); tv, tv->type, tv->name, tv->tmm_flags, flags);
} }
} }
SCMutexUnlock(&thread_store_lock); SCMutexUnlock(&thread_store_lock);
} }

Loading…
Cancel
Save