From 2494ab711543f29cb740c34f85b0ab08680612c7 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 19 Jun 2014 10:00:55 +0200 Subject: [PATCH] capmt/cwc: another destroy cleanups --- src/descrambler/capmt.c | 18 ++++++++---------- src/descrambler/cwc.c | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/descrambler/capmt.c b/src/descrambler/capmt.c index 6ae53ba5..668eb60f 100644 --- a/src/descrambler/capmt.c +++ b/src/descrambler/capmt.c @@ -1447,7 +1447,6 @@ capmt_thread(void *aux) pthread_mutex_unlock(&global_lock); } - capmt_flush_queue(capmt, 1); return NULL; } @@ -1843,14 +1842,16 @@ capmt_destroy(capmt_t *capmt) lock_assert(&global_lock); TAILQ_REMOVE(&capmts, capmt, capmt_link); capmt->capmt_running = 0; - pthread_cond_broadcast(&capmt->capmt_cond); + pthread_cond_signal(&capmt->capmt_cond); pthread_mutex_unlock(&global_lock); + tvh_write(capmt->capmt_pipe.wr, "", 1); pthread_join(capmt->capmt_tid, NULL); pthread_mutex_lock(&global_lock); tvhlog(LOG_INFO, "capmt", "mode %i %s %s port %i destroyed", capmt->capmt_oscam, capmt->capmt_oscam == CAPMT_OSCAM_TCP ? "IP address" : "sockfile", capmt->capmt_sockfile, capmt->capmt_port); + capmt_flush_queue(capmt, 1); free(capmt->capmt_id); free(capmt->capmt_sockfile); free(capmt->capmt_comment); @@ -2035,16 +2036,13 @@ capmt_init(void) void capmt_done(void) { - capmt_t *capmt, *n; + capmt_t *capmt; - for (capmt = TAILQ_FIRST(&capmts); capmt != NULL; capmt = n) { - n = TAILQ_NEXT(capmt, capmt_link); - pthread_mutex_lock(&global_lock); - tvh_write(capmt->capmt_pipe.wr, "", 1); - capmt_destroy(capmt); - pthread_mutex_unlock(&global_lock); - } dtable_delete("capmt"); + pthread_mutex_lock(&global_lock); + while ((capmt = TAILQ_FIRST(&capmts)) != NULL) + capmt_destroy(capmt); + pthread_mutex_unlock(&global_lock); } #else /* ENABLE_CAPMT */ diff --git a/src/descrambler/cwc.c b/src/descrambler/cwc.c index e2f0b8ac..264e5998 100755 --- a/src/descrambler/cwc.c +++ b/src/descrambler/cwc.c @@ -1986,9 +1986,17 @@ cwc_service_start(service_t *t) static void cwc_destroy(cwc_t *cwc) { + pthread_t tid; + + lock_assert(&cwc_mutex); TAILQ_REMOVE(&cwcs, cwc, cwc_link); cwc->cwc_running = 0; pthread_cond_signal(&cwc->cwc_cond); + tid = cwc->cwc_tid; + pthread_mutex_unlock(&cwc_mutex); + pthread_kill(tid, SIGTERM); + pthread_join(tid, NULL); + pthread_mutex_lock(&cwc_mutex); } /** @@ -2308,19 +2316,14 @@ void cwc_done(void) { cwc_t *cwc; - pthread_t tid; dtable_delete("cwc"); + pthread_mutex_lock(&global_lock); pthread_mutex_lock(&cwc_mutex); - while ((cwc = TAILQ_FIRST(&cwcs)) != NULL) { - tid = cwc->cwc_tid; + while ((cwc = TAILQ_FIRST(&cwcs)) != NULL) cwc_destroy(cwc); - pthread_mutex_unlock(&cwc_mutex); - pthread_kill(tid, SIGTERM); - pthread_join(tid, NULL); - pthread_mutex_lock(&cwc_mutex); - } pthread_mutex_unlock(&cwc_mutex); + pthread_mutex_unlock(&global_lock); }