]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Add a per threadvars thread local thread id, that starts at 0 and increments for...
authorVictor Julien <victor@inliniac.net>
Wed, 8 May 2013 11:26:49 +0000 (13:26 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 28 Jun 2013 09:02:11 +0000 (11:02 +0200)
src/threadvars.h
src/tm-threads.c

index 293322d9bc042de65c688193a5e90f6632a42c22..c589cc4c592dc6eba3d08e9f38e5c0eaed97c0b3 100644 (file)
@@ -66,12 +66,12 @@ typedef struct ThreadVars_ {
         when it encounters certain conditions like failures */
     uint8_t aof;
 
-    /** the type of thread as defined in tm-threads.h (TVT_PPT, TVT_MGMT) */
-    uint8_t type;
-
     /** no of times the thread has been restarted on failure */
     uint8_t restarted;
 
+    /** local id */
+    int id;
+
     /** queue's */
     Tmq *inq;
     Tmq *outq;
@@ -88,6 +88,10 @@ typedef struct ThreadVars_ {
     struct TmSlot_ *tm_slots;
 
     uint8_t thread_setup_flags;
+
+    /** the type of thread as defined in tm-threads.h (TVT_PPT, TVT_MGMT) */
+    uint8_t type;
+
     uint16_t cpu_affinity; /** cpu or core number to set affinity to */
     int thread_priority; /** priority (real time) for this thread. Look at threads.h */
 
index 22bb04542d8b2ffe3df1d4a90f9c9fba63792776..932d034dddba9d27a909b27b9aac38a70e0f65f0 100644 (file)
@@ -83,6 +83,10 @@ SCMutex tv_root_lock = PTHREAD_MUTEX_INITIALIZER;
  * thread encounters a failure.  Defaults to restart the failed thread */
 uint8_t tv_aof = THV_RESTART_THREAD;
 
+/** Counter for number of threadvar structs, so the number of threads we
+ *  have. */
+int g_threadvars_cnt = 0;
+
 /**
  * \brief Check if a thread flag is set.
  *
@@ -1354,6 +1358,7 @@ ThreadVars *TmThreadCreate(char *name, char *inq_name, char *inqh_name,
     SC_ATOMIC_INIT(tv->flags);
     SCMutexInit(&tv->sc_perf_pctx.m, NULL);
 
+    tv->id = g_threadvars_cnt++;
     tv->name = name;
     /* default state for every newly created thread */
     TmThreadsSetFlag(tv, THV_PAUSE);
@@ -1886,7 +1891,6 @@ TmEcode TmThreadSpawn(ThreadVars *tv)
     TmThreadWaitForFlag(tv, THV_INIT_DONE | THV_RUNNING_DONE);
 
     TmThreadAppend(tv, tv->type);
-
     return TM_ECODE_OK;
 }