mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-11 03:57:14 +00:00
FS-4836 try this
This commit is contained in:
1 parent
57f44f9f58
commit
73f022873b
5 files changed
+50
-2
No files matched your search
+40
-2
@@ -129,6 +129,7 @@ struct switch_channel {
|
||||
switch_mutex_t *dtmf_mutex;
|
||||
switch_mutex_t *flag_mutex;
|
||||
switch_mutex_t *state_mutex;
|
||||
switch_mutex_t *thread_mutex;
|
||||
switch_mutex_t *profile_mutex;
|
||||
switch_core_session_t *session;
|
||||
switch_channel_state_t state;
|
||||
@@ -352,6 +353,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel,
|
||||
switch_mutex_init(&(*channel)->dtmf_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
switch_mutex_init(&(*channel)->flag_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
switch_mutex_init(&(*channel)->state_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
switch_mutex_init(&(*channel)->thread_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
switch_mutex_init(&(*channel)->profile_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
(*channel)->hangup_cause = SWITCH_CAUSE_NONE;
|
||||
(*channel)->name = "";
|
||||
@@ -1925,6 +1927,32 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_name_state(const char *nam
|
||||
return CS_DESTROY;
|
||||
}
|
||||
|
||||
static inline void careful_set(switch_channel_t *channel, switch_channel_state_t *state, switch_channel_state_t val) {
|
||||
|
||||
if (switch_mutex_trylock(channel->thread_mutex)) {
|
||||
*state = val;
|
||||
switch_mutex_unlock(channel->thread_mutex);
|
||||
} else {
|
||||
switch_mutex_t *mutex = switch_core_session_get_mutex(channel->session);
|
||||
int x = 0;
|
||||
|
||||
for (x = 0; x < 100; x++) {
|
||||
if (switch_mutex_trylock(mutex) == SWITCH_STATUS_SUCCESS) {
|
||||
*state = val;
|
||||
switch_mutex_unlock(mutex);
|
||||
break;
|
||||
} else {
|
||||
switch_cond_next();
|
||||
}
|
||||
}
|
||||
|
||||
if (x == 100) {
|
||||
*state = val;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state(switch_channel_t *channel, switch_channel_state_t state,
|
||||
const char *file, const char *func, int line)
|
||||
{
|
||||
@@ -1950,7 +1978,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state(
|
||||
|
||||
switch_mutex_lock(channel->state_mutex);
|
||||
|
||||
channel->running_state = state;
|
||||
careful_set(channel, &channel->running_state, state);
|
||||
|
||||
if (state <= CS_DESTROY) {
|
||||
switch_event_t *event;
|
||||
@@ -2218,7 +2246,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
|
||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_DEBUG, "(%s) State Change %s -> %s\n",
|
||||
channel->name, state_names[last_state], state_names[state]);
|
||||
|
||||
channel->state = state;
|
||||
careful_set(channel, &channel->state, state);
|
||||
|
||||
if (state == CS_HANGUP && !channel->hangup_cause) {
|
||||
channel->hangup_cause = SWITCH_CAUSE_NORMAL_CLEARING;
|
||||
@@ -2240,6 +2268,16 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
|
||||
return channel->state;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_channel_state_thread_lock(switch_channel_t *channel)
|
||||
{
|
||||
switch_mutex_lock(channel->thread_mutex);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_channel_state_thread_unlock(switch_channel_t *channel)
|
||||
{
|
||||
switch_mutex_unlock(channel->thread_mutex);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_channel_event_set_basic_data(switch_channel_t *channel, switch_event_t *event)
|
||||
{
|
||||
switch_caller_profile_t *caller_profile, *originator_caller_profile = NULL, *originatee_caller_profile = NULL;
|
||||
|
||||
Reference in new issue
Block a user