forked from Mirrors/freeswitch
still try to graceful shutdown in dire cirumstances
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9490 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
860b838b63
commit
c8b8672a3e
@ -397,6 +397,7 @@ SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t *rwlock);
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock);
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t *rwlock);
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock_timeout(switch_thread_rwlock_t *rwlock, int timeout);
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock);
|
||||
|
||||
/** @} */
|
||||
|
@ -510,6 +510,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
|
||||
int use_100rel = !sofia_test_pflag(profile, PFLAG_DISABLE_100REL);
|
||||
int use_timer = !sofia_test_pflag(profile, PFLAG_DISABLE_TIMER);
|
||||
const char *supported = NULL;
|
||||
int sanity = 4;
|
||||
|
||||
switch_mutex_lock(mod_sofia_globals.mutex);
|
||||
mod_sofia_globals.threads++;
|
||||
@ -658,8 +659,11 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
|
||||
}
|
||||
|
||||
while (profile->inuse) {
|
||||
switch_yield(100000);
|
||||
switch_yield(5000000);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "waiting for %d session(s)\n", profile->inuse);
|
||||
if (!sanity--) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
nua_destroy(profile->nua);
|
||||
|
||||
|
@ -170,6 +170,22 @@ SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwl
|
||||
return apr_thread_rwlock_trywrlock(rwlock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock_timeout(switch_thread_rwlock_t *rwlock, int timeout)
|
||||
{
|
||||
int sanity = timeout * 2;
|
||||
|
||||
while (sanity) {
|
||||
if (switch_thread_rwlock_trywrlock(rwlock) == SWITCH_STATUS_SUCCESS) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
sanity--;
|
||||
switch_yield(500000);
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
|
||||
{
|
||||
return apr_thread_rwlock_unlock(rwlock);
|
||||
|
@ -424,9 +424,11 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
|
||||
|
||||
switch_core_session_hupall_endpoint(ptr, SWITCH_CAUSE_SYSTEM_SHUTDOWN);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
|
||||
switch_thread_rwlock_wrlock(ptr->rwlock);
|
||||
switch_thread_rwlock_unlock(ptr->rwlock);
|
||||
|
||||
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_thread_rwlock_unlock(ptr->rwlock);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Endpoint '%s'\n", ptr->interface_name);
|
||||
switch_core_hash_delete(loadable_modules.endpoint_hash, ptr->interface_name);
|
||||
@ -505,9 +507,12 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Application '%s'\n", ptr->interface_name);
|
||||
switch_core_session_hupall_matching_var(SWITCH_CURRENT_APPLICATION_VARIABLE, ptr->interface_name, SWITCH_CAUSE_SYSTEM_SHUTDOWN);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
|
||||
switch_thread_rwlock_wrlock(ptr->rwlock);
|
||||
switch_thread_rwlock_unlock(ptr->rwlock);
|
||||
|
||||
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_thread_rwlock_unlock(ptr->rwlock);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
|
||||
}
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "application");
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
|
||||
@ -528,8 +533,13 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting API Function '%s'\n", ptr->interface_name);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
|
||||
switch_thread_rwlock_wrlock(ptr->rwlock);
|
||||
switch_thread_rwlock_unlock(ptr->rwlock);
|
||||
|
||||
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_thread_rwlock_unlock(ptr->rwlock);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for existing references.\n");
|
||||
}
|
||||
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "api");
|
||||
|
Loading…
Reference in New Issue
Block a user