diff --git a/src/tm-threads.c b/src/tm-threads.c index e24fa216f6..415302f126 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -60,20 +60,32 @@ typedef struct TmVarSlot_ { */ inline int TmThreadsCheckFlag(ThreadVars *tv, uint8_t flag) { int r; - spin_lock(&tv->flags_spinlock); + if (spin_lock(&tv->flags_spinlock) != 0) { + SCLogError(SC_SPINLOCK_ERROR,"spin lock errno=%d",errno); + return 0; + } + r = (tv->flags & flag); spin_unlock(&tv->flags_spinlock); return r; } inline void TmThreadsSetFlag(ThreadVars *tv, uint8_t flag) { - spin_lock(&tv->flags_spinlock); + if (spin_lock(&tv->flags_spinlock) != 0) { + SCLogError(SC_SPINLOCK_ERROR,"spin lock errno=%d",errno); + return; + } + tv->flags |= flag; spin_unlock(&tv->flags_spinlock); } inline void TmThreadsUnsetFlag(ThreadVars *tv, uint8_t flag) { - spin_lock(&tv->flags_spinlock); + if (spin_lock(&tv->flags_spinlock) != 0) { + SCLogError(SC_SPINLOCK_ERROR,"spin lock errno=%d",errno); + return; + } + tv->flags &= ~flag; spin_unlock(&tv->flags_spinlock); } @@ -225,6 +237,7 @@ void *TmThreadsSlot1NoInOut(void *td) { memset(&s->s.slot_pq, 0, sizeof(PacketQueue)); TmThreadsSetFlag(tv, THV_INIT_DONE); + while(run) { TmThreadTestThreadUnPaused(tv); @@ -932,6 +945,7 @@ void TmThreadTestThreadUnPaused(ThreadVars *tv) { while (TmThreadsCheckFlag(tv, THV_PAUSE)) { usleep(100); + if (TmThreadsCheckFlag(tv, THV_KILL)) break; } @@ -1083,12 +1097,14 @@ TmEcode TmThreadWaitOnThreadInit(void) started = TRUE; } - if (TmThreadsCheckFlag(tv, THV_CLOSED) || - TmThreadsCheckFlag(tv, THV_FAILED)) - { + if (TmThreadsCheckFlag(tv, THV_FAILED)) { printf("Thread \"%s\" failed to initialize...\n", tv->name); return TM_ECODE_FAILED; } + if (TmThreadsCheckFlag(tv, THV_CLOSED)) { + printf("Thread \"%s\" closed on initialization...\n", tv->name); + return TM_ECODE_FAILED; + } } if (i == TVT_MGMT) mgt_num++; diff --git a/src/util-error.h b/src/util-error.h index 5e1910f97b..d2e89d464c 100644 --- a/src/util-error.h +++ b/src/util-error.h @@ -17,6 +17,7 @@ typedef enum { SC_INVALID_CHECKSUM, SC_SPRINTF_ERROR, SC_INVALID_ARGUMENT, + SC_SPINLOCK_ERROR, } SCError; const char *SCErrorToString(SCError);