From: Anoop Saldanha Date: Wed, 28 Mar 2012 05:17:36 +0000 (+0530) Subject: cleanup killing threads. As a consequence fixes invalid read/writes in tmqh flow X-Git-Tag: suricata-1.3beta1~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fea6a426a5eaf905d915acbe1692214eb1baf7a8;p=thirdparty%2Fsuricata.git cleanup killing threads. As a consequence fixes invalid read/writes in tmqh flow --- diff --git a/src/tm-threads.c b/src/tm-threads.c index 9625f1a78b..ba7a7318ca 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -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);