make the in_use count be a function instead of a constant to fix race
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@750 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
parent
7841b7635b
commit
a6f5392dd6
|
@ -536,7 +536,6 @@ struct zap_span {
|
||||||
char *name;
|
char *name;
|
||||||
uint32_t span_id;
|
uint32_t span_id;
|
||||||
uint32_t chan_count;
|
uint32_t chan_count;
|
||||||
uint32_t active_count;
|
|
||||||
zap_span_flag_t flags;
|
zap_span_flag_t flags;
|
||||||
struct zap_io_interface *zio;
|
struct zap_io_interface *zio;
|
||||||
zio_event_cb_t event_callback;
|
zio_event_cb_t event_callback;
|
||||||
|
@ -639,6 +638,7 @@ OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event
|
||||||
OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback);
|
OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback);
|
||||||
OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan);
|
OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan);
|
||||||
OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan);
|
OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan);
|
||||||
|
OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count);
|
||||||
OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan);
|
OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan);
|
||||||
OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan);
|
OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan);
|
||||||
OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan);
|
OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan);
|
||||||
|
|
|
@ -240,6 +240,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request)
|
||||||
ss7_boost_request_status_t st;
|
ss7_boost_request_status_t st;
|
||||||
char ani[128] = "";
|
char ani[128] = "";
|
||||||
char *gr = NULL;
|
char *gr = NULL;
|
||||||
|
uint32_t count = 0;
|
||||||
|
|
||||||
if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) {
|
if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) {
|
||||||
zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n");
|
zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n");
|
||||||
|
@ -247,7 +248,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request)
|
||||||
return ZAP_FAIL;
|
return ZAP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (span->active_count >= span->chan_count) {
|
zap_span_channel_use_count(span, &count);
|
||||||
|
|
||||||
|
if (count >= span->chan_count) {
|
||||||
zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n");
|
zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n");
|
||||||
*zchan = NULL;
|
*zchan = NULL;
|
||||||
return ZAP_FAIL;
|
return ZAP_FAIL;
|
||||||
|
|
|
@ -887,12 +887,6 @@ OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel
|
||||||
|
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
if (zchan->state == ZAP_CHANNEL_STATE_DOWN) {
|
|
||||||
zchan->span->active_count++;
|
|
||||||
} else if (state == ZAP_CHANNEL_STATE_DOWN) {
|
|
||||||
zchan->span->active_count--;
|
|
||||||
}
|
|
||||||
|
|
||||||
zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE);
|
zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE);
|
||||||
zap_set_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE);
|
zap_set_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE);
|
||||||
zchan->last_state = zchan->state;
|
zchan->last_state = zchan->state;
|
||||||
|
@ -906,11 +900,32 @@ OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel
|
||||||
return ok ? ZAP_SUCCESS : ZAP_FAIL;
|
return ok ? ZAP_SUCCESS : ZAP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count)
|
||||||
|
{
|
||||||
|
uint32_t j;
|
||||||
|
|
||||||
|
*count = 0;
|
||||||
|
|
||||||
|
if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED)) {
|
||||||
|
return ZAP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(j = 1; j <= span->chan_count && span->channels[j]; j++) {
|
||||||
|
if (span->channels[j]) {
|
||||||
|
if (zap_test_flag(span->channels[j], ZAP_CHANNEL_INUSE)) {
|
||||||
|
(*count)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ZAP_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan)
|
OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan)
|
||||||
{
|
{
|
||||||
zap_status_t status = ZAP_FAIL;
|
zap_status_t status = ZAP_FAIL;
|
||||||
zap_channel_t *check;
|
zap_channel_t *check;
|
||||||
uint32_t i,j;
|
uint32_t i, j, count;
|
||||||
zap_span_t *span = NULL;
|
zap_span_t *span = NULL;
|
||||||
uint32_t span_max;
|
uint32_t span_max;
|
||||||
|
|
||||||
|
@ -923,7 +938,9 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t
|
||||||
return ZAP_FAIL;
|
return ZAP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (span->active_count >= span->chan_count) {
|
zap_span_channel_use_count(span, &count);
|
||||||
|
|
||||||
|
if (count >= span->chan_count) {
|
||||||
zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n");
|
zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n");
|
||||||
*zchan = NULL;
|
*zchan = NULL;
|
||||||
return ZAP_FAIL;
|
return ZAP_FAIL;
|
||||||
|
|
Loading…
Reference in New Issue