From efeaf2069eb1f9c3a415b7a92db60a7a7ec1c5cb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 3 Oct 2011 18:53:17 -0500 Subject: [PATCH] FS-3594 --resolve --- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 74de4aab3e..49732723bd 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -625,6 +625,7 @@ struct sofia_profile { uint32_t event_timeout; int watchdog_enabled; switch_mutex_t *gw_mutex; + uint32_t queued_events; }; struct private_object { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 9601697ab4..775722f6ef 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1137,7 +1137,8 @@ void sofia_process_dispatch_event(sofia_dispatch_event_t **dep) sofia_dispatch_event_t *de = *dep; nua_handle_t *nh = de->nh; nua_t *nua = de->nua; - + sofia_profile_t *profile = de->profile; + *dep = NULL; our_sofia_event_callback(de->data->e_event, de->data->e_status, de->data->e_phrase, de->nua, de->profile, @@ -1145,6 +1146,10 @@ void sofia_process_dispatch_event(sofia_dispatch_event_t **dep) nua_destroy_event(de->event); su_free(nh->nh_home, de); + + switch_mutex_lock(profile->flag_mutex); + profile->queued_events--; + switch_mutex_unlock(profile->flag_mutex); nua_handle_unref(nh); nua_stack_unref(nua); @@ -1245,6 +1250,10 @@ void sofia_event_callback(nua_event_t event, { sofia_dispatch_event_t *de; + switch_mutex_lock(profile->flag_mutex); + profile->queued_events++; + switch_mutex_unlock(profile->flag_mutex); + de = su_alloc(nh->nh_home, sizeof(*de)); memset(de, 0, sizeof(*de)); nua_save_event(nua, de->event); @@ -1972,7 +1981,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void nua_shutdown(profile->nua); sanity = 10; - while (!sofia_test_pflag(profile, PFLAG_SHUTDOWN)) { + while (!sofia_test_pflag(profile, PFLAG_SHUTDOWN) || profile->queued_events > 0) { su_root_step(profile->s_root, 1000); if (!--sanity) { break;