From 4cb323b5acdc2910a558bd8ef23868ce802b6a40 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Feb 2008 20:26:06 +0000 Subject: [PATCH] fix shutdown race git-svn-id: http://svn.openzap.org/svn/openzap/trunk@395 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_analog.c | 2 +- libs/openzap/src/zap_io.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index b4c1087462..ef9d696dc5 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -218,7 +218,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) assert(interval != 0); - while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; zap_size_t dlen = 0; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 2987164c69..05a26beda2 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -233,6 +233,11 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { + while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + zap_log(ZAP_LOG_INFO, "Waiting for thread to exit on channel %u:%u\n", zchan->span_id, zchan->chan_id); + zap_sleep(500); + } + zap_buffer_destroy(&zchan->digit_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); @@ -1993,9 +1998,9 @@ zap_status_t zap_global_destroy(void) { unsigned int i,j; time_end(); - + + globals.running = 0; zap_span_close_all(); - globals.running = 0; zap_sleep(1000); for(i = 1; i <= globals.span_index; i++) {