]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3594 --resolve
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 3 Oct 2011 23:53:17 +0000 (18:53 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 3 Oct 2011 23:53:17 +0000 (18:53 -0500)
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c

index 74de4aab3edb991d5812e76f25c97449ce8ca720..49732723bd2b589cb397e3734b22c0e685044ad6 100644 (file)
@@ -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 {
index 9601697ab4f3e6f286bf170e689a93dc1e05c258..775722f6efd2cb63943ede215c2a42a71a6b5154 100644 (file)
@@ -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;