From 428931bce29ec7ee0ca1eafc29cd52821db97407 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 5 Apr 2010 16:01:08 -0400 Subject: [PATCH] Use the pendingchans queue only on request by signaling modules. Remove suggest_chan_id member and add a span flag instead. --- libs/freetdm/src/ftdm_io.c | 16 ++++++++++------ libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 2 +- .../src/ftmod/ftmod_libpri/ftmod_libpri.c | 2 +- .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 3 ++- libs/freetdm/src/include/freetdm.h | 1 - libs/freetdm/src/include/ftdm_types.h | 4 +++- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 6a1b21c6ad..1b27f91130 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -412,7 +412,9 @@ static ftdm_status_t ftdm_span_destroy(ftdm_span_t *span) } /* destroy final basic resources of the span data structure */ - ftdm_queue_destroy(&span->pendingchans); + if (span->pendingchans) { + ftdm_queue_destroy(&span->pendingchans); + } ftdm_mutex_unlock(span->mutex); ftdm_mutex_destroy(&span->mutex); ftdm_safe_free(span->signal_data); @@ -518,9 +520,6 @@ FT_DECLARE(ftdm_status_t) ftdm_span_create(ftdm_io_interface_t *fio, ftdm_span_t status = ftdm_mutex_create(&new_span->mutex); ftdm_assert(status == FTDM_SUCCESS, "mutex creation failed\n"); - status = ftdm_queue_create(&new_span->pendingchans, SPAN_PENDING_CHANS_QUEUE_SIZE); - ftdm_assert(status == FTDM_SUCCESS, "span chans queue creation failed\n"); - ftdm_set_flag(new_span, FTDM_SPAN_CONFIGURED); new_span->span_id = ++globals.span_index; new_span->fio = fio; @@ -1163,7 +1162,9 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_set_state(ftdm_channel_t *ftdmchan, ftdm_ ftdm_mutex_lock(ftdmchan->span->mutex); ftdm_set_flag(ftdmchan->span, FTDM_SPAN_STATE_CHANGE); - ftdm_queue_enqueue(ftdmchan->span->pendingchans, ftdmchan); + if (ftdmchan->span->pendingchans) { + ftdm_queue_enqueue(ftdmchan->span->pendingchans, ftdmchan); + } ftdm_mutex_unlock(ftdmchan->span->mutex); ftdmchan->last_state = ftdmchan->state; @@ -1329,7 +1330,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc return FTDM_FAIL; } - if (span->channel_request && !span->suggest_chan_id) { + if (span->channel_request && !ftdm_test_flag(span, FTDM_SPAN_SUGGEST_CHAN_ID)) { ftdm_set_caller_data(span, caller_data); return span->channel_request(span, 0, direction, caller_data, ftdmchan); } @@ -3266,6 +3267,9 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *spa va_list ap; va_start(ap, sig_cb); status = mod->sig_configure(span, sig_cb, ap); + if (status == FTDM_SUCCESS && ftdm_test_flag(span, FTDM_SPAN_USE_CHAN_QUEUE)) { + status = ftdm_queue_create(&span->pendingchans, SPAN_PENDING_CHANS_QUEUE_SIZE); + } va_end(ap); } else { ftdm_log(FTDM_LOG_ERROR, "can't find '%s'\n", type); diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index 3445599d13..e980ab8936 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -2385,7 +2385,7 @@ static FIO_SIG_CONFIGURE_FUNCTION(ftdm_isdn_configure_span) if ((isdn_data->opts & FTDM_ISDN_OPT_SUGGEST_CHANNEL)) { span->channel_request = isdn_channel_request; - span->suggest_chan_id = 1; + ftdm_set_flag(span, FTDM_SPAN_SUGGEST_CHAN_ID); } span->state_map = &isdn_state_map; diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c index 929a874657..871769e49e 100644 --- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c @@ -1331,7 +1331,7 @@ static FIO_SIG_CONFIGURE_FUNCTION(ftdm_libpri_configure_span) if ((isdn_data->opts & FTMOD_LIBPRI_OPT_SUGGEST_CHANNEL)) { span->channel_request = isdn_channel_request; - span->suggest_chan_id = 1; + ftdm_set_flag(span, FTDM_SPAN_SUGGEST_CHAN_ID); } span->state_map = &isdn_state_map; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index e7317e3679..c2ca3db7c4 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -2239,7 +2239,8 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) span->get_span_sig_status = sangoma_boost_get_span_sig_status; span->set_span_sig_status = sangoma_boost_set_span_sig_status; span->state_map = &boost_state_map; - span->suggest_chan_id = 0; + ftdm_clear_flag(span, FTDM_SPAN_SUGGEST_CHAN_ID); + ftdm_set_flag(span, FTDM_SPAN_USE_CHAN_QUEUE); if (sigmod_iface) { /* the core will do the hunting */ span->channel_request = NULL; diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 0900c62800..04c30abc67 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -654,7 +654,6 @@ struct ftdm_span { char *type; char *dtmf_hangup; size_t dtmf_hangup_len; - int suggest_chan_id; ftdm_state_map_t *state_map; ftdm_caller_data_t default_caller_data; ftdm_queue_t *pendingchans; diff --git a/libs/freetdm/src/include/ftdm_types.h b/libs/freetdm/src/include/ftdm_types.h index 7260358c8f..cf12bc9a2c 100644 --- a/libs/freetdm/src/include/ftdm_types.h +++ b/libs/freetdm/src/include/ftdm_types.h @@ -325,7 +325,9 @@ typedef enum { FTDM_SPAN_STATE_CHANGE = (1 << 2), FTDM_SPAN_SUSPENDED = (1 << 3), FTDM_SPAN_IN_THREAD = (1 << 4), - FTDM_SPAN_STOP_THREAD = (1 << 5) + FTDM_SPAN_STOP_THREAD = (1 << 5), + FTDM_SPAN_USE_CHAN_QUEUE = (1 << 6), + FTDM_SPAN_SUGGEST_CHAN_ID = (1 << 7), } ftdm_span_flag_t; typedef enum {