From 89048d71ad1ff6576ed0974fb103054152c1fc0e Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sun, 3 Nov 2019 10:37:06 +0100 Subject: [PATCH] threading: fix flags handling by using uint32_t everywhere --- src/threadvars.h | 30 +++++++++++++++--------------- src/tm-threads.c | 8 ++++---- src/tm-threads.h | 8 ++++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/threadvars.h b/src/threadvars.h index b72ab572b6..2fec2fa56b 100644 --- a/src/threadvars.h +++ b/src/threadvars.h @@ -32,26 +32,26 @@ struct TmSlot_; /** Thread flags set and read by threads to control the threads */ -#define THV_USE 1 /** thread is in use */ -#define THV_INIT_DONE (1 << 1) /** thread initialization done */ -#define THV_PAUSE (1 << 2) /** signal thread to pause itself */ -#define THV_PAUSED (1 << 3) /** the thread is paused atm */ -#define THV_KILL (1 << 4) /** thread has been asked to cleanup and exit */ -#define THV_FAILED (1 << 5) /** thread has encountered an error and failed */ -#define THV_CLOSED (1 << 6) /** thread done, should be joinable */ +#define THV_USE BIT_U32(0) /** thread is in use */ +#define THV_INIT_DONE BIT_U32(1) /** thread initialization done */ +#define THV_PAUSE BIT_U32(2) /** signal thread to pause itself */ +#define THV_PAUSED BIT_U32(3) /** the thread is paused atm */ +#define THV_KILL BIT_U32(4) /** thread has been asked to cleanup and exit */ +#define THV_FAILED BIT_U32(5) /** thread has encountered an error and failed */ +#define THV_CLOSED BIT_U32(6) /** thread done, should be joinable */ /* used to indicate the thread is going through de-init. Introduced as more * of a hack for solving stream-timeout-shutdown. Is set by the main thread. */ -#define THV_DEINIT (1 << 7) -#define THV_RUNNING_DONE (1 << 8) /** thread has completed running and is entering - * the de-init phase */ -#define THV_KILL_PKTACQ (1 << 9) /**< flag thread to stop packet acq */ -#define THV_FLOW_LOOP (1 << 10) /**< thread is in flow shutdown loop */ +#define THV_DEINIT BIT_U32(7) +#define THV_RUNNING_DONE BIT_U32(8) /** thread has completed running and is entering + * the de-init phase */ +#define THV_KILL_PKTACQ BIT_U32(9) /**< flag thread to stop packet acq */ +#define THV_FLOW_LOOP BIT_U32(10) /**< thread is in flow shutdown loop */ /** signal thread's capture method to create a fake packet to force through * the engine. This is to force timely handling of maintenance taks like * rule reloads even if no packets are read by the capture method. */ -#define THV_CAPTURE_INJECT_PKT (1<<11) -#define THV_DEAD (1 << 12) /**< thread has been joined with pthread_join() */ +#define THV_CAPTURE_INJECT_PKT BIT_U32(11) +#define THV_DEAD BIT_U32(12) /**< thread has been joined with pthread_join() */ /** \brief Per thread variable structure */ typedef struct ThreadVars_ { @@ -60,7 +60,7 @@ typedef struct ThreadVars_ { char *printable_name; char *thread_group_name; - SC_ATOMIC_DECLARE(unsigned int, flags); + SC_ATOMIC_DECLARE(uint32_t, flags); /** TmModule::flags for each module part of this thread */ uint8_t tmm_flags; diff --git a/src/tm-threads.c b/src/tm-threads.c index 3fe852d289..067f426781 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -86,7 +86,7 @@ SCMutex tv_root_lock = SCMUTEX_INITIALIZER; * \retval 1 flag is set. * \retval 0 flag is not set. */ -int TmThreadsCheckFlag(ThreadVars *tv, uint16_t flag) +int TmThreadsCheckFlag(ThreadVars *tv, uint32_t flag) { return (SC_ATOMIC_GET(tv->flags) & flag) ? 1 : 0; } @@ -94,7 +94,7 @@ int TmThreadsCheckFlag(ThreadVars *tv, uint16_t flag) /** * \brief Set a thread flag. */ -void TmThreadsSetFlag(ThreadVars *tv, uint16_t flag) +void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag) { SC_ATOMIC_OR(tv->flags, flag); } @@ -102,7 +102,7 @@ void TmThreadsSetFlag(ThreadVars *tv, uint16_t flag) /** * \brief Unset a thread flag. */ -void TmThreadsUnsetFlag(ThreadVars *tv, uint16_t flag) +void TmThreadsUnsetFlag(ThreadVars *tv, uint32_t flag) { SC_ATOMIC_AND(tv->flags, ~flag); } @@ -1978,7 +1978,7 @@ void TmThreadTestThreadUnPaused(ThreadVars *tv) * * \param tv Pointer to the TV instance. */ -void TmThreadWaitForFlag(ThreadVars *tv, uint16_t flags) +void TmThreadWaitForFlag(ThreadVars *tv, uint32_t flags) { while (!TmThreadsCheckFlag(tv, flags)) { SleepUsec(100); diff --git a/src/tm-threads.h b/src/tm-threads.h index 4157d728bc..3ad5b0e4ce 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -134,10 +134,10 @@ void TmThreadCheckThreadState(void); TmEcode TmThreadWaitOnThreadInit(void); ThreadVars *TmThreadsGetCallingThread(void); -int TmThreadsCheckFlag(ThreadVars *, uint16_t); -void TmThreadsSetFlag(ThreadVars *, uint16_t); -void TmThreadsUnsetFlag(ThreadVars *, uint16_t); -void TmThreadWaitForFlag(ThreadVars *, uint16_t); +int TmThreadsCheckFlag(ThreadVars *, uint32_t); +void TmThreadsSetFlag(ThreadVars *, uint32_t); +void TmThreadsUnsetFlag(ThreadVars *, uint32_t); +void TmThreadWaitForFlag(ThreadVars *, uint32_t); TmEcode TmThreadsSlotVarRun (ThreadVars *tv, Packet *p, TmSlot *slot); -- 2.47.2