]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
cleanup killing threads. As a consequence fixes invalid read/writes in tmqh flow
authorAnoop Saldanha <poonaatsoc@gmail.com>
Wed, 28 Mar 2012 05:17:36 +0000 (10:47 +0530)
committerVictor Julien <victor@inliniac.net>
Wed, 28 Mar 2012 12:55:26 +0000 (14:55 +0200)
src/tm-threads.c

index 9625f1a78b84d49353da233f92a1bd6150216b80..ba7a7318ca478d9344d0eb7f460f578aa808907b 100644 (file)
@@ -1395,40 +1395,34 @@ void TmThreadKillThread(ThreadVars *tv)
     TmThreadsSetFlag(tv, THV_KILL);
     TmThreadsSetFlag(tv, THV_DEINIT);
 
-    if (tv->inq != NULL) {
-        /* signal the queue for the number of users */
-        if (tv->InShutdownHandler != NULL) {
-            tv->InShutdownHandler(tv);
-        }
-        for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) {
-            if (tv->inq->q_type == 0)
-                SCCondSignal(&trans_q[tv->inq->id].cond_q);
-            else
-                SCCondSignal(&data_queues[tv->inq->id].cond_q);
+    /* to be sure, signal more */
+    int cnt = 0;
+    while (1) {
+        if (TmThreadsCheckFlag(tv, THV_CLOSED)) {
+            SCLogDebug("signalled the thread %" PRId32 " times", cnt);
+            break;
         }
 
-        /* to be sure, signal more */
-        int cnt = 0;
-        while (1) {
-            if (TmThreadsCheckFlag(tv, THV_CLOSED)) {
-                SCLogDebug("signalled the thread %" PRId32 " times", cnt);
-                break;
-            }
-
-            cnt++;
+        cnt++;
 
-            if (tv->InShutdownHandler != NULL) {
-                tv->InShutdownHandler(tv);
-            }
+        if (tv->InShutdownHandler != NULL) {
+            tv->InShutdownHandler(tv);
+        }
+        if (tv->inq != NULL) {
             for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) {
                 if (tv->inq->q_type == 0)
                     SCCondSignal(&trans_q[tv->inq->id].cond_q);
                 else
                     SCCondSignal(&data_queues[tv->inq->id].cond_q);
             }
-            usleep(100);
+            SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id);
         }
-        SCLogDebug("signalled tv->inq->id %" PRIu32 "", tv->inq->id);
+
+        if (tv->cond != NULL ) {
+            pthread_cond_broadcast(tv->cond);
+        }
+
+        usleep(100);
     }
 
     if (tv->outctx != NULL) {
@@ -1441,20 +1435,6 @@ void TmThreadKillThread(ThreadVars *tv)
         }
     }
 
-    if (tv->cond != NULL ) {
-        int cnt = 0;
-        while (1) {
-            if (TmThreadsCheckFlag(tv, THV_CLOSED)) {
-                SCLogDebug("signalled the thread %" PRId32 " times", cnt);
-                break;
-            }
-
-            cnt++;
-            pthread_cond_broadcast(tv->cond);
-            usleep(100);
-        }
-    }
-
     /* join it */
     pthread_join(tv->t, NULL);
     SCLogDebug("thread %s stopped", tv->name);