]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threading: fix flags handling by using uint32_t everywhere
authorVictor Julien <victor@inliniac.net>
Sun, 3 Nov 2019 09:37:06 +0000 (10:37 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 7 Feb 2020 14:43:10 +0000 (15:43 +0100)
src/threadvars.h
src/tm-threads.c
src/tm-threads.h

index b72ab572b67c4f0741533291174eaa01556ee2c2..2fec2fa56b5e798488362f6b50d0b73f4cb2bd8b 100644 (file)
 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;
index 3fe852d289453301af174cc4a57d74a9d029d4aa..067f4267811ab24952906b6966123252ff34c407 100644 (file)
@@ -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);
index 4157d728bc9b5f8913204f46ceae0c91b172e685..3ad5b0e4ceeab007bdf143fd85583741c3be3206 100644 (file)
@@ -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);