make crash protection a runtime option instead of a compile-time option

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5123 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2007-05-10 16:56:29 +00:00
1 parent c07224852c
commit ab34a26079
10 files changed
+130 -133

No files matched your search

+39 -39
View File
@@ -41,7 +41,7 @@ static struct {
uint32_t session_count;
uint32_t session_limit;
switch_size_t session_id;
} runtime;
} session_manager;
#ifdef SWITCH_DEBUG_RWLOCKS
@@ -53,8 +53,8 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_locate(char *uuid_st
switch_core_session_t *session = NULL;
if (uuid_str) {
switch_mutex_lock(runtime.session_table_mutex);
if ((session = switch_core_hash_find(runtime.session_table, uuid_str))) {
switch_mutex_lock(session_manager.session_table_mutex);
if ((session = switch_core_hash_find(session_manager.session_table, uuid_str))) {
/* Acquire a read lock on the session */
#ifdef SWITCH_DEBUG_RWLOCKS
if (switch_core_session_perform_read_lock(session, file, func, line) != SWITCH_STATUS_SUCCESS) {
@@ -65,7 +65,7 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_locate(char *uuid_st
session = NULL;
}
}
switch_mutex_unlock(runtime.session_table_mutex);
switch_mutex_unlock(session_manager.session_table_mutex);
}
/* if its not NULL, now it's up to you to rwunlock this */
@@ -80,8 +80,8 @@ SWITCH_DECLARE(void) switch_core_session_hupall(switch_call_cause_t cause)
switch_channel_t *channel;
uint32_t loops = 0;
switch_mutex_lock(runtime.session_table_mutex);
for (hi = switch_hash_first(runtime.memory_pool, runtime.session_table); hi; hi = switch_hash_next(hi)) {
switch_mutex_lock(session_manager.session_table_mutex);
for (hi = switch_hash_first(session_manager.memory_pool, session_manager.session_table); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
if (val) {
session = (switch_core_session_t *) val;
@@ -90,13 +90,13 @@ SWITCH_DECLARE(void) switch_core_session_hupall(switch_call_cause_t cause)
switch_core_session_kill_channel(session, SWITCH_SIG_KILL);
}
}
switch_mutex_unlock(runtime.session_table_mutex);
switch_mutex_unlock(session_manager.session_table_mutex);
while (runtime.session_count > 0) {
while (session_manager.session_count > 0) {
switch_yield(100000);
if (++loops == 100) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Giving up with %d session%s remaining\n",
runtime.session_count, runtime.session_count == 1 ? "" : "s");
session_manager.session_count, session_manager.session_count == 1 ? "" : "s");
break;
}
}
@@ -107,8 +107,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_message_send(char *uuid_str,
switch_core_session_t *session = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_lock(runtime.session_table_mutex);
if ((session = switch_core_hash_find(runtime.session_table, uuid_str)) != 0) {
switch_mutex_lock(session_manager.session_table_mutex);
if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) {
/* Acquire a read lock on the session or forget it the channel is dead */
if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
if (switch_channel_get_state(session->channel) < CS_HANGUP) {
@@ -117,7 +117,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_message_send(char *uuid_str,
switch_core_session_rwunlock(session);
}
}
switch_mutex_unlock(runtime.session_table_mutex);
switch_mutex_unlock(session_manager.session_table_mutex);
return status;
}
@@ -127,8 +127,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_event_send(char *uuid_str, s
switch_core_session_t *session = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_lock(runtime.session_table_mutex);
if ((session = switch_core_hash_find(runtime.session_table, uuid_str)) != 0) {
switch_mutex_lock(session_manager.session_table_mutex);
if ((session = switch_core_hash_find(session_manager.session_table, uuid_str)) != 0) {
/* Acquire a read lock on the session or forget it the channel is dead */
if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
if (switch_channel_get_state(session->channel) < CS_HANGUP) {
@@ -137,7 +137,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_event_send(char *uuid_str, s
switch_core_session_rwunlock(session);
}
}
switch_mutex_unlock(runtime.session_table_mutex);
switch_mutex_unlock(session_manager.session_table_mutex);
return status;
}
@@ -662,12 +662,12 @@ SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session_t **session
switch_scheduler_del_task_group((*session)->uuid_str);
switch_mutex_lock(runtime.session_table_mutex);
switch_core_hash_delete(runtime.session_table, (*session)->uuid_str);
if (runtime.session_count) {
runtime.session_count--;
switch_mutex_lock(session_manager.session_table_mutex);
switch_core_hash_delete(session_manager.session_table, (*session)->uuid_str);
if (session_manager.session_count) {
session_manager.session_count--;
}
switch_mutex_unlock(runtime.session_table_mutex);
switch_mutex_unlock(session_manager.session_table_mutex);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DESTROY) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data((*session)->channel, event);
@@ -750,11 +750,11 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
assert(endpoint_interface != NULL);
switch_mutex_lock(runtime.session_table_mutex);
count = runtime.session_count;
switch_mutex_unlock(runtime.session_table_mutex);
switch_mutex_lock(session_manager.session_table_mutex);
count = session_manager.session_count;
switch_mutex_unlock(session_manager.session_table_mutex);
if ((count + 1) > runtime.session_limit) {
if ((count + 1) > session_manager.session_limit) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Limit!\n");
return NULL;
}
@@ -812,23 +812,23 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
switch_thread_rwlock_create(&session->rwlock, session->pool);
snprintf(session->name, sizeof(session->name), "%"SWITCH_SIZE_T_FMT, session->id);
switch_mutex_lock(runtime.session_table_mutex);
session->id = runtime.session_id++;
switch_core_hash_insert(runtime.session_table, session->uuid_str, session);
runtime.session_count++;
switch_mutex_unlock(runtime.session_table_mutex);
switch_mutex_lock(session_manager.session_table_mutex);
session->id = session_manager.session_id++;
switch_core_hash_insert(session_manager.session_table, session->uuid_str, session);
session_manager.session_count++;
switch_mutex_unlock(session_manager.session_table_mutex);
return session;
}
SWITCH_DECLARE(uint32_t) switch_core_session_count(void)
{
return runtime.session_count;
return session_manager.session_count;
}
SWITCH_DECLARE(switch_size_t) switch_core_session_id(void)
{
return runtime.session_id;
return session_manager.session_id;
}
@@ -867,21 +867,21 @@ SWITCH_DECLARE(char *) switch_core_session_get_uuid(switch_core_session_t *sessi
SWITCH_DECLARE(uint32_t) switch_core_session_limit(uint32_t new_limit)
{
if (new_limit) {
runtime.session_limit = new_limit;
session_manager.session_limit = new_limit;
}
return runtime.session_limit;
return session_manager.session_limit;
}
void switch_core_session_init(switch_memory_pool_t *pool)
{
memset(&runtime, 0, sizeof(runtime));
runtime.session_limit = 1000;
runtime.session_id = 1;
runtime.memory_pool = pool;
switch_core_hash_init(&runtime.session_table, runtime.memory_pool);
switch_mutex_init(&runtime.session_table_mutex, SWITCH_MUTEX_NESTED, runtime.memory_pool);
memset(&session_manager, 0, sizeof(session_manager));
session_manager.session_limit = 1000;
session_manager.session_id = 1;
session_manager.memory_pool = pool;
switch_core_hash_init(&session_manager.session_table, session_manager.memory_pool);
switch_mutex_init(&session_manager.session_table_mutex, SWITCH_MUTEX_NESTED, session_manager.memory_pool);
}