git-svn-id: http://svn.openzap.org/svn/openzap/trunk@436 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Anthony Minessale 2008-04-02 17:49:18 +00:00
parent 83459e33f8
commit 7f8ee9981a
1 changed files with 25 additions and 22 deletions

View File

@ -717,21 +717,17 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c
zap_span_t *span; zap_span_t *span;
uint32_t span_max; uint32_t span_max;
zap_mutex_lock(globals.mutex); if (span_id) {
if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { if (globals.spans[span_id].active_count >= globals.spans[span_id].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;
goto done; return ZAP_FAIL;
} }
if (span_id && globals.spans[span_id].channel_request) { if (globals.spans[span_id].channel_request) {
zap_mutex_unlock(globals.mutex); return globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan);
status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan);
goto done;
} }
if (span_id) {
span_max = span_id; span_max = span_id;
j = span_id; j = span_id;
} else { } else {
@ -746,15 +742,17 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c
for(;;) { for(;;) {
if (direction == ZAP_TOP_DOWN) { if (direction == ZAP_TOP_DOWN) {
if (j > span_max) { if (j > span_max) {
break; goto done;
} }
} else { } else {
if (j == 0) { if (j == 0) {
break; goto done;
} }
} }
span = &globals.spans[j]; span = &globals.spans[j];
zap_mutex_lock(span->mutex);
if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) {
goto next_loop; goto next_loop;
} }
@ -779,7 +777,11 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c
check = &span->channels[i]; check = &span->channels[i];
if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED)) { if (zap_test_flag(check, ZAP_CHANNEL_READY) &&
!zap_test_flag(check, ZAP_CHANNEL_INUSE) &&
!zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) &&
check->state == ZAP_CHANNEL_STATE_DOWN
) {
status = check->zio->open(check); status = check->zio->open(check);
@ -787,6 +789,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c
zap_set_flag(check, ZAP_CHANNEL_INUSE); zap_set_flag(check, ZAP_CHANNEL_INUSE);
zap_channel_open_chan(check); zap_channel_open_chan(check);
*zchan = check; *zchan = check;
zap_mutex_unlock(span->mutex);
goto done; goto done;
} }
} }
@ -796,11 +799,12 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c
} else { } else {
i--; i--;
} }
} }
next_loop: next_loop:
zap_mutex_unlock(span->mutex);
if (direction == ZAP_TOP_DOWN) { if (direction == ZAP_TOP_DOWN) {
j++; j++;
} else { } else {
@ -809,7 +813,6 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c
} }
done: done:
zap_mutex_unlock(globals.mutex);
return status; return status;
} }