ok maybe this will fix the conditional mutext race we will readlock the session during any callbacks and cancel the operation if read_lock fails

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2709 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2006-09-16 00:43:58 +00:00
parent aa2a793e28
commit 555bd0af08
3 changed files with 47 additions and 28 deletions

View File

@@ -90,8 +90,8 @@ struct switch_core_session {
switch_audio_resampler_t *read_resampler;
switch_audio_resampler_t *write_resampler;
//switch_mutex_t *mutex;
//switch_thread_cond_t *cond;
switch_mutex_t *mutex;
switch_thread_cond_t *cond;
switch_thread_rwlock_t *rwlock;
@@ -2489,13 +2489,13 @@ static void switch_core_standard_on_hold(switch_core_session_t *session)
SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session_t *session)
{
return;
/* If trylock fails the signal is already awake so we needn't bother
/* If trylock fails the signal is already awake so we needn't bother */
if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_signal(session->cond);
switch_mutex_unlock(session->mutex);
}
*/
}
SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session_t *session)
@@ -2555,7 +2555,7 @@ static int handle_fatality(int sig)
SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
{
switch_channel_state_t state = CS_NEW, laststate = CS_HANGUP, midstate = CS_DONE;
switch_channel_state_t state = CS_NEW, laststate = CS_HANGUP, midstate = CS_DONE, endstate;
const switch_endpoint_interface_t *endpoint_interface;
const switch_state_handler_table_t *driver_state_handler = NULL;
const switch_state_handler_table_t *application_state_handler = NULL;
@@ -2607,7 +2607,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
driver_state_handler = endpoint_interface->state_handler;
assert(driver_state_handler != NULL);
//switch_mutex_lock(session->mutex);
switch_mutex_lock(session->mutex);
while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
if (state != laststate) {
@@ -2886,20 +2886,20 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
laststate = midstate;
}
if (state >= CS_HANGUP) {
endstate = switch_channel_get_state(session->channel);
if (endstate >= CS_HANGUP) {
goto done;
}
if (midstate == switch_channel_get_state(session->channel)) {
//switch_thread_cond_wait(session->cond, session->mutex);
switch_yield(10000);
} else {
switch_yield(1000);
if (midstate == endstate) {
switch_thread_cond_wait(session->cond, session->mutex);
}
}
done:
//switch_mutex_unlock(session->mutex);
switch_mutex_unlock(session->mutex);
#ifdef CRASH_PROT
apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), NULL);
@@ -3151,9 +3151,9 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
session->enc_read_frame.data = session->enc_read_buf;
session->enc_read_frame.buflen = sizeof(session->enc_read_buf);
//switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
switch_thread_rwlock_create(&session->bug_rwlock, session->pool);
//switch_thread_cond_create(&session->cond, session->pool);
switch_thread_cond_create(&session->cond, session->pool);
switch_thread_rwlock_create(&session->rwlock, session->pool);
switch_mutex_lock(runtime.session_table_mutex);