Detect errors in the spin locks which somehow seems to fix some deadlocking withing valgrind.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent 32830ff43d
commit 4fb4dd59e4

@ -60,20 +60,32 @@ typedef struct TmVarSlot_ {
*/ */
inline int TmThreadsCheckFlag(ThreadVars *tv, uint8_t flag) { inline int TmThreadsCheckFlag(ThreadVars *tv, uint8_t flag) {
int r; 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); r = (tv->flags & flag);
spin_unlock(&tv->flags_spinlock); spin_unlock(&tv->flags_spinlock);
return r; return r;
} }
inline void TmThreadsSetFlag(ThreadVars *tv, uint8_t flag) { 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; tv->flags |= flag;
spin_unlock(&tv->flags_spinlock); spin_unlock(&tv->flags_spinlock);
} }
inline void TmThreadsUnsetFlag(ThreadVars *tv, uint8_t flag) { 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; tv->flags &= ~flag;
spin_unlock(&tv->flags_spinlock); spin_unlock(&tv->flags_spinlock);
} }
@ -225,6 +237,7 @@ void *TmThreadsSlot1NoInOut(void *td) {
memset(&s->s.slot_pq, 0, sizeof(PacketQueue)); memset(&s->s.slot_pq, 0, sizeof(PacketQueue));
TmThreadsSetFlag(tv, THV_INIT_DONE); TmThreadsSetFlag(tv, THV_INIT_DONE);
while(run) { while(run) {
TmThreadTestThreadUnPaused(tv); TmThreadTestThreadUnPaused(tv);
@ -932,6 +945,7 @@ void TmThreadTestThreadUnPaused(ThreadVars *tv)
{ {
while (TmThreadsCheckFlag(tv, THV_PAUSE)) { while (TmThreadsCheckFlag(tv, THV_PAUSE)) {
usleep(100); usleep(100);
if (TmThreadsCheckFlag(tv, THV_KILL)) if (TmThreadsCheckFlag(tv, THV_KILL))
break; break;
} }
@ -1083,12 +1097,14 @@ TmEcode TmThreadWaitOnThreadInit(void)
started = TRUE; started = TRUE;
} }
if (TmThreadsCheckFlag(tv, THV_CLOSED) || if (TmThreadsCheckFlag(tv, THV_FAILED)) {
TmThreadsCheckFlag(tv, THV_FAILED))
{
printf("Thread \"%s\" failed to initialize...\n", tv->name); printf("Thread \"%s\" failed to initialize...\n", tv->name);
return TM_ECODE_FAILED; 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++; if (i == TVT_MGMT) mgt_num++;

@ -17,6 +17,7 @@ typedef enum {
SC_INVALID_CHECKSUM, SC_INVALID_CHECKSUM,
SC_SPRINTF_ERROR, SC_SPRINTF_ERROR,
SC_INVALID_ARGUMENT, SC_INVALID_ARGUMENT,
SC_SPINLOCK_ERROR,
} SCError; } SCError;
const char *SCErrorToString(SCError); const char *SCErrorToString(SCError);

Loading…
Cancel
Save