From: Victor Julien Date: Wed, 10 Dec 2014 10:49:30 +0000 (+0100) Subject: Thread registration: id's start at 1 X-Git-Tag: suricata-2.1beta3~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c51b23e9436312e5939286a8335332b9bdfd70b;p=thirdparty%2Fsuricata.git Thread registration: id's start at 1 Start thread id's at 1, so that in flow's we can use 0 to indicate a thread id hasn't been set in it yet. --- diff --git a/src/tm-threads.c b/src/tm-threads.c index 59754c0ae4..60b18c1daf 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -1994,7 +1994,7 @@ void TmThreadsListThreads(void) t = &thread_store.threads[s]; if (t == NULL || t->in_use == 0) continue; - SCLogInfo("Thread %"PRIuMAX", %s type %d, tv %p", (uintmax_t)s, t->name, t->type, t->tv); + SCLogInfo("Thread %"PRIuMAX", %s type %d, tv %p", (uintmax_t)s+1, t->name, t->type, t->tv); } SCMutexUnlock(&thread_store_lock); @@ -2023,7 +2023,7 @@ int TmThreadsRegisterThread(ThreadVars *tv, const int type) t->in_use = 1; SCMutexUnlock(&thread_store_lock); - return (int)s; + return (int)(s+1); } } @@ -2043,18 +2043,21 @@ int TmThreadsRegisterThread(ThreadVars *tv, const int type) thread_store.threads_size += STEP; SCMutexUnlock(&thread_store_lock); - return (int)s; + return (int)(s+1); } #undef STEP void TmThreadsUnregisterThread(const int id) { SCMutexLock(&thread_store_lock); - if (id < 0 || id >= (int)thread_store.threads_size) + if (id <= 0 || id > (int)thread_store.threads_size) return; + /* id is one higher than index */ + int idx = id - 1; + /* reset thread_id, which serves as clearing the record */ - thread_store.threads[id].in_use = 0; + thread_store.threads[idx].in_use = 0; /* check if we have at least one registered thread left */ size_t s; @@ -2080,12 +2083,14 @@ end: * \note if packet was not accepted, it's still the responsibility * of the caller. */ -int TmThreadsInjectPacketsById(Packet **packets, int id) +int TmThreadsInjectPacketsById(Packet **packets, const int id) { - if (id < 0 || id >= (int)thread_store.threads_size) + if (id <= 0 || id > (int)thread_store.threads_size) return 0; - Thread *t = &thread_store.threads[id]; + int idx = id - 1; + + Thread *t = &thread_store.threads[idx]; ThreadVars *tv = t->tv; if (tv == NULL || tv->stream_pq == NULL)