Converting threadvar flags to atomic vars to avoid using the old spinlock

remotes/origin/master-1.1.x
Pablo Rincon 15 years ago committed by Victor Julien
parent b8f5a6a4fc
commit fcff1ce7f4

@ -51,8 +51,7 @@ typedef struct ThreadVars_ {
char *name; char *name;
char *thread_group_name; char *thread_group_name;
uint8_t flags; SC_ATOMIC_DECLARE(unsigned short, flags);
SCSpinlock flags_spinlock;
/** aof(action on failure) determines what should be done with the thread /** aof(action on failure) determines what should be done with the thread
when it encounters certain conditions like failures */ when it encounters certain conditions like failures */

@ -75,40 +75,21 @@ uint8_t tv_aof = THV_RESTART_THREAD;
* \retval 0 flag is not set * \retval 0 flag is not set
*/ */
int TmThreadsCheckFlag(ThreadVars *tv, uint8_t flag) { int TmThreadsCheckFlag(ThreadVars *tv, uint8_t flag) {
int r; return (SC_ATOMIC_GET(tv->flags) & flag)? 1 : 0;
if (SCSpinLock(&(tv)->flags_spinlock) != 0) {
SCLogError(SC_ERR_SPINLOCK,"spin lock errno=%d",errno);
return 0;
}
r = (tv->flags & flag);
SCSpinUnlock(&tv->flags_spinlock);
return r;
} }
/** /**
* \brief Set a thread flag * \brief Set a thread flag
*/ */
void TmThreadsSetFlag(ThreadVars *tv, uint8_t flag) { void TmThreadsSetFlag(ThreadVars *tv, uint8_t flag) {
if (SCSpinLock(&tv->flags_spinlock) != 0) { SC_ATOMIC_OR(tv->flags, flag);
SCLogError(SC_ERR_SPINLOCK,"spin lock errno=%d",errno);
return;
}
tv->flags |= flag;
SCSpinUnlock(&tv->flags_spinlock);
} }
/** /**
* \brief Unset a thread flag * \brief Unset a thread flag
*/ */
void TmThreadsUnsetFlag(ThreadVars *tv, uint8_t flag) { void TmThreadsUnsetFlag(ThreadVars *tv, uint8_t flag) {
if (SCSpinLock(&tv->flags_spinlock) != 0) { SC_ATOMIC_NAND(tv->flags, flag);
SCLogError(SC_ERR_SPINLOCK,"spin lock errno=%d",errno);
return;
}
tv->flags &= ~flag;
SCSpinUnlock(&tv->flags_spinlock);
} }
/* 1 slot functions */ /* 1 slot functions */
@ -809,7 +790,7 @@ ThreadVars *TmThreadCreate(char *name, char *inq_name, char *inqh_name,
goto error; goto error;
memset(tv, 0, sizeof(ThreadVars)); memset(tv, 0, sizeof(ThreadVars));
SCSpinInit(&tv->flags_spinlock, PTHREAD_PROCESS_PRIVATE); SC_ATOMIC_INIT(tv->flags);
SCMutexInit(&tv->sc_perf_pctx.m, NULL); SCMutexInit(&tv->sc_perf_pctx.m, NULL);
tv->name = name; tv->name = name;

Loading…
Cancel
Save