提交 ce2a9d26 authored 作者: Anthony Minessale's avatar Anthony Minessale

add more mutexed flag ops

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1664 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 4052fc3e
...@@ -117,7 +117,10 @@ SWITCH_DECLARE(unsigned char) switch_char_to_rfc2833(char key); ...@@ -117,7 +117,10 @@ SWITCH_DECLARE(unsigned char) switch_char_to_rfc2833(char key);
\param obj the object to set the flags on \param obj the object to set the flags on
\param flag the or'd list of flags to set \param flag the or'd list of flags to set
*/ */
#define switch_set_flag_locked(obj, flag) switch_mutex_lock(obj->flag_mutex); (obj)->flags |= (flag); switch_mutex_unlock(obj->flag_mutex); #define switch_set_flag_locked(obj, flag) assert(obj->flag_mutex != NULL);\
switch_mutex_lock(obj->flag_mutex);\
(obj)->flags |= (flag);\
switch_mutex_unlock(obj->flag_mutex);
/*! /*!
\brief Clear a flag on an arbitrary object \brief Clear a flag on an arbitrary object
......
...@@ -90,6 +90,7 @@ struct private_object { ...@@ -90,6 +90,7 @@ struct private_object {
unsigned int codecs; unsigned int codecs;
unsigned short samprate; unsigned short samprate;
switch_mutex_t *mutex; switch_mutex_t *mutex;
switch_mutex_t *flag_mutex;
//switch_thread_cond_t *cond; //switch_thread_cond_t *cond;
}; };
...@@ -344,7 +345,7 @@ static switch_status_t iax_set_codec(struct private_object *tech_pvt, struct iax ...@@ -344,7 +345,7 @@ static switch_status_t iax_set_codec(struct private_object *tech_pvt, struct iax
} }
if (!strcasecmp(dname, "l16")) { if (!strcasecmp(dname, "l16")) {
switch_set_flag(tech_pvt, TFLAG_LINEAR); switch_set_flag_locked(tech_pvt, TFLAG_LINEAR);
} }
if (switch_core_codec_init(&tech_pvt->read_codec, if (switch_core_codec_init(&tech_pvt->read_codec,
dname, dname,
...@@ -376,7 +377,7 @@ static switch_status_t iax_set_codec(struct private_object *tech_pvt, struct iax ...@@ -376,7 +377,7 @@ static switch_status_t iax_set_codec(struct private_object *tech_pvt, struct iax
tech_pvt->read_frame.codec = &tech_pvt->read_codec; tech_pvt->read_frame.codec = &tech_pvt->read_codec;
switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec); switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
switch_set_flag(tech_pvt, TFLAG_CODEC); switch_set_flag_locked(tech_pvt, TFLAG_CODEC);
} }
tech_pvt->codec = chosen; tech_pvt->codec = chosen;
tech_pvt->codecs = local_cap; tech_pvt->codecs = local_cap;
...@@ -437,7 +438,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) ...@@ -437,7 +438,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
iax_set_private(tech_pvt->iax_session, tech_pvt); iax_set_private(tech_pvt->iax_session, tech_pvt);
switch_set_flag(tech_pvt, TFLAG_IO); switch_set_flag_locked(tech_pvt, TFLAG_IO);
switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
//switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session)); //switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session));
...@@ -494,8 +495,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) ...@@ -494,8 +495,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
tech_pvt = switch_core_session_get_private(session); tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
switch_clear_flag(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_clear_flag(tech_pvt, TFLAG_VOICE); switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
//switch_thread_cond_signal(tech_pvt->cond); //switch_thread_cond_signal(tech_pvt->cond);
if (tech_pvt->read_codec.implementation) { if (tech_pvt->read_codec.implementation) {
...@@ -509,7 +510,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) ...@@ -509,7 +510,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
if (tech_pvt->iax_session) { if (tech_pvt->iax_session) {
if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) { if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
iax_hangup(tech_pvt->iax_session, "Hangup"); iax_hangup(tech_pvt->iax_session, "Hangup");
switch_set_flag(tech_pvt, TFLAG_HANGUP); switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
} }
iax_session_destroy(&tech_pvt->iax_session); iax_session_destroy(&tech_pvt->iax_session);
} }
...@@ -530,8 +531,8 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int ...@@ -530,8 +531,8 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
tech_pvt = switch_core_session_get_private(session); tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
switch_clear_flag(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_clear_flag(tech_pvt, TFLAG_VOICE); switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
//switch_thread_cond_signal(tech_pvt->cond); //switch_thread_cond_signal(tech_pvt->cond);
...@@ -612,7 +613,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch ...@@ -612,7 +613,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
} }
if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) { if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
switch_clear_flag(tech_pvt, TFLAG_VOICE); switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
if (!tech_pvt->read_frame.datalen) { if (!tech_pvt->read_frame.datalen) {
continue; continue;
} }
...@@ -737,6 +738,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session, ...@@ -737,6 +738,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
if ((tech_pvt = if ((tech_pvt =
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) { (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt)); memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
channel = switch_core_session_get_channel(*new_session); channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt); switch_core_session_set_private(*new_session, tech_pvt);
tech_pvt->session = *new_session; tech_pvt->session = *new_session;
...@@ -781,7 +783,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session, ...@@ -781,7 +783,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
caller_profile->caller_id_name, caller_profile->destination_number, NULL, 0, req, cap); caller_profile->caller_id_name, caller_profile->destination_number, NULL, 0, req, cap);
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -988,6 +990,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) ...@@ -988,6 +990,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
(struct private_object *) switch_core_session_alloc(session, (struct private_object *) switch_core_session_alloc(session,
sizeof(struct private_object))) != 0) { sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt)); memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt); switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session; tech_pvt->session = session;
...@@ -1042,11 +1045,14 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) ...@@ -1042,11 +1045,14 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
if (tech_pvt) { if (tech_pvt) {
switch_channel_t *channel; switch_channel_t *channel;
switch_mutex_lock(tech_pvt->flag_mutex);
switch_clear_flag(tech_pvt, TFLAG_IO); switch_clear_flag(tech_pvt, TFLAG_IO);
switch_clear_flag(tech_pvt, TFLAG_VOICE); switch_clear_flag(tech_pvt, TFLAG_VOICE);
switch_mutex_unlock(tech_pvt->flag_mutex);
if ((channel = switch_core_session_get_channel(tech_pvt->session)) != 0) { if ((channel = switch_core_session_get_channel(tech_pvt->session)) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
switch_set_flag(tech_pvt, TFLAG_HANGUP); switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED); switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
//switch_thread_cond_signal(tech_pvt->cond); //switch_thread_cond_signal(tech_pvt->cond);
iaxevent->session = NULL; iaxevent->session = NULL;
...@@ -1079,7 +1085,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) ...@@ -1079,7 +1085,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame; tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen); memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
/* wake up the i/o thread */ /* wake up the i/o thread */
switch_set_flag(tech_pvt, TFLAG_VOICE); switch_set_flag_locked(tech_pvt, TFLAG_VOICE);
//switch_thread_cond_signal(tech_pvt->cond); //switch_thread_cond_signal(tech_pvt->cond);
} }
} }
......
...@@ -92,6 +92,7 @@ struct private_object { ...@@ -92,6 +92,7 @@ struct private_object {
PABLIO_Stream *audio_out; PABLIO_Stream *audio_out;
int indev; int indev;
int outdev; int outdev;
switch_mutex_t *flag_mutex;
}; };
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan) SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
...@@ -177,7 +178,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) ...@@ -177,7 +178,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) { if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
switch_channel_hangup(channel, SWITCH_CAUSE_NO_ANSWER); switch_channel_hangup(channel, SWITCH_CAUSE_NO_ANSWER);
} else { } else {
switch_set_flag(tech_pvt, TFLAG_IO); switch_set_flag_locked(tech_pvt, TFLAG_IO);
/* Move Channel's State Machine to RING */ /* Move Channel's State Machine to RING */
switch_channel_set_state(channel, CS_RING); switch_channel_set_state(channel, CS_RING);
...@@ -245,7 +246,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) ...@@ -245,7 +246,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
tech_pvt = switch_core_session_get_private(session); tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
switch_clear_flag(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_core_hash_delete(globals.call_hash, tech_pvt->call_id); switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
switch_core_codec_destroy(&tech_pvt->read_codec); switch_core_codec_destroy(&tech_pvt->read_codec);
...@@ -269,7 +270,7 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int ...@@ -269,7 +270,7 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
tech_pvt = switch_core_session_get_private(session); tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
switch_clear_flag(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_IO);
deactivate_audio_device(tech_pvt); deactivate_audio_device(tech_pvt);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
...@@ -425,7 +426,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s ...@@ -425,7 +426,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_PROGRESS:
{ {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engage Early Media\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engage Early Media\n");
switch_set_flag(tech_pvt, TFLAG_IO); switch_set_flag_locked(tech_pvt, TFLAG_IO);
} }
default: default:
break; break;
...@@ -524,6 +525,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session, ...@@ -524,6 +525,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
if ((tech_pvt = if ((tech_pvt =
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) { (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt)); memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
channel = switch_core_session_get_channel(*new_session); channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt); switch_core_session_set_private(*new_session, tech_pvt);
tech_pvt->session = *new_session; tech_pvt->session = *new_session;
...@@ -550,7 +552,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session, ...@@ -550,7 +552,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
} }
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -838,6 +840,7 @@ static switch_status_t place_call(char *dest, switch_stream_handle_t *stream) ...@@ -838,6 +840,7 @@ static switch_status_t place_call(char *dest, switch_stream_handle_t *stream)
switch_core_session_add_stream(session, NULL); switch_core_session_add_stream(session, NULL);
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) { if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt)); memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt); switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session; tech_pvt->session = session;
...@@ -947,7 +950,7 @@ static switch_status_t answer_call(char *callid, switch_stream_handle_t *stream) ...@@ -947,7 +950,7 @@ static switch_status_t answer_call(char *callid, switch_stream_handle_t *stream)
if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid)) != 0) { if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid)) != 0) {
channel = switch_core_session_get_channel(tech_pvt->session); channel = switch_core_session_get_channel(tech_pvt->session);
assert(channel != NULL); assert(channel != NULL);
switch_set_flag(tech_pvt, TFLAG_ANSWER); switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
switch_channel_answer(channel); switch_channel_answer(channel);
} else { } else {
stream->write_function(stream, "NO SUCH CALL"); stream->write_function(stream, "NO SUCH CALL");
......
...@@ -116,6 +116,7 @@ struct private_object { ...@@ -116,6 +116,7 @@ struct private_object {
switch_buffer_t *dtmf_buffer; switch_buffer_t *dtmf_buffer;
unsigned int skip_read_frames; unsigned int skip_read_frames;
unsigned int skip_write_frames; unsigned int skip_write_frames;
switch_mutex_t *flag_mutex;
#ifdef DOTRACE #ifdef DOTRACE
int fd; int fd;
int fd2; int fd2;
...@@ -337,7 +338,7 @@ static switch_status_t wanpipe_on_hangup(switch_core_session_t *session) ...@@ -337,7 +338,7 @@ static switch_status_t wanpipe_on_hangup(switch_core_session_t *session)
tech_pvt = switch_core_session_get_private(session); tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
switch_set_flag(tech_pvt, TFLAG_BYE); switch_set_flag_locked(tech_pvt, TFLAG_BYE);
if (!switch_test_flag(tech_pvt, TFLAG_NOSIG)) { if (!switch_test_flag(tech_pvt, TFLAG_NOSIG)) {
chanmap = tech_pvt->spri->private_info; chanmap = tech_pvt->spri->private_info;
...@@ -656,9 +657,11 @@ static switch_status_t wanpipe_kill_channel(switch_core_session_t *session, int ...@@ -656,9 +657,11 @@ static switch_status_t wanpipe_kill_channel(switch_core_session_t *session, int
tech_pvt = switch_core_session_get_private(session); tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
switch_mutex_lock(tech_pvt->flag_mutex);
switch_set_flag(tech_pvt, TFLAG_BYE); switch_set_flag(tech_pvt, TFLAG_BYE);
switch_clear_flag(tech_pvt, TFLAG_MEDIA); switch_clear_flag(tech_pvt, TFLAG_MEDIA);
switch_mutex_unlock(tech_pvt->flag_mutex);
sangoma_socket_close(&tech_pvt->socket); sangoma_socket_close(&tech_pvt->socket);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
...@@ -737,6 +740,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session, ...@@ -737,6 +740,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
switch_core_session_add_stream(*new_session, NULL); switch_core_session_add_stream(*new_session, NULL);
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) { if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt)); memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
channel = switch_core_session_get_channel(*new_session); channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt); switch_core_session_set_private(*new_session, tech_pvt);
tech_pvt->session = *new_session; tech_pvt->session = *new_session;
...@@ -806,7 +810,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session, ...@@ -806,7 +810,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
switch_set_flag(tech_pvt, TFLAG_NOSIG); switch_set_flag_locked(tech_pvt, TFLAG_NOSIG);
snprintf(name, sizeof(name), "WanPipe/%s/nosig-%04x", bchan, rand() & 0xffff); snprintf(name, sizeof(name), "WanPipe/%s/nosig-%04x", bchan, rand() & 0xffff);
switch_channel_set_name(channel, name); switch_channel_set_name(channel, name);
switch_channel_set_caller_profile(channel, caller_profile); switch_channel_set_caller_profile(channel, caller_profile);
...@@ -901,7 +905,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session, ...@@ -901,7 +905,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
} }
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -1118,6 +1122,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri ...@@ -1118,6 +1122,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
switch_core_session_add_stream(session, NULL); switch_core_session_add_stream(session, NULL);
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt)); memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt); switch_core_session_set_private(session, tech_pvt);
sprintf(name, "s%dc%d", spri->span, event->ring.channel); sprintf(name, "s%dc%d", spri->span, event->ring.channel);
...@@ -1148,7 +1153,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri ...@@ -1148,7 +1153,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
} }
switch_set_flag(tech_pvt, TFLAG_INBOUND); switch_set_flag_locked(tech_pvt, TFLAG_INBOUND);
tech_pvt->spri = spri; tech_pvt->spri = spri;
tech_pvt->cause = -1; tech_pvt->cause = -1;
......
...@@ -154,6 +154,7 @@ struct private_object { ...@@ -154,6 +154,7 @@ struct private_object {
char dtmfbuf[WOOMERA_STRLEN]; char dtmfbuf[WOOMERA_STRLEN];
switch_caller_profile_t *caller_profile; switch_caller_profile_t *caller_profile;
struct woomera_event_queue event_queue; struct woomera_event_queue event_queue;
switch_mutex_t *flag_mutex;
}; };
typedef struct private_object private_object; typedef struct private_object private_object;
...@@ -230,7 +231,7 @@ static switch_status_t woomerachan_on_init(switch_core_session_t *session) ...@@ -230,7 +231,7 @@ static switch_status_t woomerachan_on_init(switch_core_session_t *session)
switch_core_session_set_write_codec(session, &tech_pvt->write_codec); switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
switch_set_flag(tech_pvt, TFLAG_ACTIVATE); switch_set_flag_locked(tech_pvt, TFLAG_ACTIVATE);
switch_core_session_launch_thread(session, woomera_channel_thread_run, session); switch_core_session_launch_thread(session, woomera_channel_thread_run, session);
...@@ -483,6 +484,7 @@ static switch_status_t woomerachan_outgoing_channel(switch_core_session_t *sessi ...@@ -483,6 +484,7 @@ static switch_status_t woomerachan_outgoing_channel(switch_core_session_t *sessi
if ((tech_pvt = if ((tech_pvt =
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) { (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt)); memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
tech_pvt->profile = &default_profile; tech_pvt->profile = &default_profile;
channel = switch_core_session_get_channel(*new_session); channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt); switch_core_session_set_private(*new_session, tech_pvt);
...@@ -510,7 +512,7 @@ static switch_status_t woomerachan_outgoing_channel(switch_core_session_t *sessi ...@@ -510,7 +512,7 @@ static switch_status_t woomerachan_outgoing_channel(switch_core_session_t *sessi
} }
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -907,13 +909,13 @@ static int tech_activate(private_object * tech_pvt) ...@@ -907,13 +909,13 @@ static int tech_activate(private_object * tech_pvt)
woomera_message_parse(tech_pvt->command_channel, woomera_message_parse(tech_pvt->command_channel,
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue); &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue);
} else { } else {
switch_set_flag(tech_pvt, TFLAG_PARSE_INCOMING); switch_set_flag_locked(tech_pvt, TFLAG_PARSE_INCOMING);
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "LISTEN%s", WOOMERA_RECORD_SEPERATOR); woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
if (woomera_message_parse(tech_pvt->command_channel, if (woomera_message_parse(tech_pvt->command_channel,
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) { &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name); tech_pvt->profile->name);
switch_set_flag(tech_pvt, TFLAG_ABORT); switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1; globals.panic = 1;
} }
} }
...@@ -949,7 +951,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj) ...@@ -949,7 +951,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
for (;;) { for (;;) {
if (globals.panic) { if (globals.panic) {
switch_set_flag(tech_pvt, TFLAG_ABORT); switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
} }
if (switch_test_flag(tech_pvt, TFLAG_ABORT)) { if (switch_test_flag(tech_pvt, TFLAG_ABORT)) {
...@@ -959,12 +961,12 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj) ...@@ -959,12 +961,12 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
} }
if (switch_test_flag(tech_pvt, TFLAG_ACTIVATE)) { if (switch_test_flag(tech_pvt, TFLAG_ACTIVATE)) {
switch_clear_flag(tech_pvt, TFLAG_ACTIVATE); switch_clear_flag_locked(tech_pvt, TFLAG_ACTIVATE);
tech_activate(tech_pvt); tech_activate(tech_pvt);
} }
if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) { if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
switch_clear_flag(tech_pvt, TFLAG_ANSWER); switch_clear_flag_locked(tech_pvt, TFLAG_ANSWER);
#ifdef USE_ANSWER #ifdef USE_ANSWER
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s", tech_pvt->call_info.callid, woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s", tech_pvt->call_info.callid,
WOOMERA_RECORD_SEPERATOR); WOOMERA_RECORD_SEPERATOR);
...@@ -973,7 +975,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj) ...@@ -973,7 +975,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
&tech_pvt->event_queue) < 0) { &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name); tech_pvt->profile->name);
switch_set_flag(tech_pvt, TFLAG_ABORT); switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1; globals.panic = 1;
continue; continue;
} }
...@@ -989,11 +991,11 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj) ...@@ -989,11 +991,11 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
&tech_pvt->event_queue) < 0) { &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name); tech_pvt->profile->name);
switch_set_flag(tech_pvt, TFLAG_ABORT); switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1; globals.panic = 1;
continue; continue;
} }
switch_clear_flag(tech_pvt, TFLAG_DTMF); switch_clear_flag_locked(tech_pvt, TFLAG_DTMF);
memset(tech_pvt->dtmfbuf, 0, sizeof(tech_pvt->dtmfbuf)); memset(tech_pvt->dtmfbuf, 0, sizeof(tech_pvt->dtmfbuf));
switch_mutex_unlock(tech_pvt->iolock); switch_mutex_unlock(tech_pvt->iolock);
} }
...@@ -1007,7 +1009,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj) ...@@ -1007,7 +1009,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000)); ((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000));
if (elapsed > tech_pvt->timeout) { if (elapsed > tech_pvt->timeout) {
/* call timed out! */ /* call timed out! */
switch_set_flag(tech_pvt, TFLAG_ABORT); switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
} }
} }
#endif #endif
...@@ -1020,7 +1022,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj) ...@@ -1020,7 +1022,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
(res = woomera_message_parse(tech_pvt->command_channel, &wmsg, 100, tech_pvt->profile, NULL)) != 0) { (res = woomera_message_parse(tech_pvt->command_channel, &wmsg, 100, tech_pvt->profile, NULL)) != 0) {
if (res < 0 || !strcasecmp(wmsg.command, "HANGUP")) { if (res < 0 || !strcasecmp(wmsg.command, "HANGUP")) {
switch_set_flag(tech_pvt, TFLAG_ABORT); switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
continue; continue;
} else if (!strcasecmp(wmsg.command, "DTMF")) { } else if (!strcasecmp(wmsg.command, "DTMF")) {
/* /*
...@@ -1043,8 +1045,8 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj) ...@@ -1043,8 +1045,8 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
char *cid_num; char *cid_num;
char *ip; char *ip;
char *p; char *p;
switch_clear_flag(tech_pvt, TFLAG_PARSE_INCOMING); switch_clear_flag_locked(tech_pvt, TFLAG_PARSE_INCOMING);
switch_set_flag(tech_pvt, TFLAG_INCOMING); switch_set_flag_locked(tech_pvt, TFLAG_INCOMING);
tech_pvt->call_info = wmsg; tech_pvt->call_info = wmsg;
exten = woomera_message_header(&wmsg, "Local-Number"); exten = woomera_message_header(&wmsg, "Local-Number");
...@@ -1088,7 +1090,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj) ...@@ -1088,7 +1090,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) { &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name); tech_pvt->profile->name);
switch_set_flag(tech_pvt, TFLAG_ABORT); switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1; globals.panic = 1;
continue; continue;
} }
...@@ -1242,6 +1244,7 @@ static void *woomera_thread_run(void *obj) ...@@ -1242,6 +1244,7 @@ static void *woomera_thread_run(void *obj)
if ((tech_pvt = if ((tech_pvt =
(struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) { (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt)); memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
tech_pvt->profile = &default_profile; tech_pvt->profile = &default_profile;
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt); switch_core_session_set_private(session, tech_pvt);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论