From aef0ec60ba86d3886f50cfb7d4ab73eeec21a12c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 5 Dec 2014 10:38:50 -0500 Subject: [PATCH] unlock mutexes when thread is cancelled --- mediator.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mediator.c b/mediator.c index dad79e1..0751437 100644 --- a/mediator.c +++ b/mediator.c @@ -279,11 +279,12 @@ static void *callid_fetcher(void *p) { * polling the same callids. */ pthread_cond_broadcast(&callid_process_cond); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_cleanup_push((void *) pthread_mutex_unlock, &callid_process_lock); do pthread_cond_wait(&process_idle_cond, &callid_process_lock); while (process_threads_busy); + pthread_cleanup_pop(1); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); - pthread_mutex_unlock(&callid_process_lock); pthread_mutex_lock(&mediator_count_lock); syslog(LOG_DEBUG, "Overall %"PRIu64" CDRs created so far.", mediator_count); @@ -342,9 +343,11 @@ static void *callid_worker(void *p) { #endif process_threads_busy--; - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_cond_signal(&process_idle_cond); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_cleanup_push((void *) pthread_mutex_unlock, &callid_process_lock); pthread_cond_wait(&callid_process_cond, &callid_process_lock); + pthread_cleanup_pop(0); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); process_threads_busy++;