freetdm: core - lock the channel on ftdm_channel_read_event()

ftmod_zt - not locking the channel on zt_channel_next_event(), minor changes
This commit is contained in:
Arnaldo Pereira 2010-12-21 16:32:02 -02:00
parent 7732a67598
commit 723a598c24
2 changed files with 11 additions and 5 deletions

View File

@ -1142,14 +1142,17 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read_event(ftdm_channel_t *ftdmchan, ftdm
ftdm_span_t *span = ftdmchan->span; ftdm_span_t *span = ftdmchan->span;
ftdm_assert_return(span->fio != NULL, FTDM_FAIL, "No I/O module attached to this span!\n"); ftdm_assert_return(span->fio != NULL, FTDM_FAIL, "No I/O module attached to this span!\n");
ftdm_channel_lock(ftdmchan);
if (!span->fio->channel_next_event) { if (!span->fio->channel_next_event) {
ftdm_log(FTDM_LOG_ERROR, "channel_next_event method not implemented in module %s!", span->fio->name); ftdm_log(FTDM_LOG_ERROR, "channel_next_event method not implemented in module %s!", span->fio->name);
return FTDM_NOTIMPL; status = FTDM_NOTIMPL;
goto done;
} }
status = span->fio->channel_next_event(ftdmchan, event); status = span->fio->channel_next_event(ftdmchan, event);
if (status != FTDM_SUCCESS) { if (status != FTDM_SUCCESS) {
return status; goto done;
} }
/* before returning the event to the user we do some core operations with certain OOB events */ /* before returning the event to the user we do some core operations with certain OOB events */
@ -1177,6 +1180,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read_event(ftdm_channel_t *ftdmchan, ftdm
break; break;
} }
done:
ftdm_channel_unlock(ftdmchan);
return status; return status;
} }

View File

@ -1007,7 +1007,8 @@ FIO_CHANNEL_NEXT_EVENT_FUNCTION(zt_channel_next_event)
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_EVENT)) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_EVENT)) {
ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_EVENT); ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_EVENT);
if (ioctl(ftdmchan->sockfd, codes.GETEVENT, &zt_event_id) == -1) { if (ioctl(ftdmchan->sockfd, codes.GETEVENT, &zt_event_id) == -1) {
snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Failed retrieving event from channel: %s\n",
strerror(errno));
return FTDM_FAIL; return FTDM_FAIL;
} }
@ -1044,7 +1045,7 @@ FIO_CHANNEL_NEXT_EVENT_FUNCTION(zt_channel_next_event)
case ZT_EVENT_RINGOFFHOOK: case ZT_EVENT_RINGOFFHOOK:
{ {
if (ftdmchan->type == FTDM_CHAN_TYPE_FXS || (ftdmchan->type == FTDM_CHAN_TYPE_EM && ftdmchan->state != FTDM_CHANNEL_STATE_UP)) { if (ftdmchan->type == FTDM_CHAN_TYPE_FXS || (ftdmchan->type == FTDM_CHAN_TYPE_EM && ftdmchan->state != FTDM_CHANNEL_STATE_UP)) {
ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_OFFHOOK); ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK);
event_id = FTDM_OOB_OFFHOOK; event_id = FTDM_OOB_OFFHOOK;
} else if (ftdmchan->type == FTDM_CHAN_TYPE_FXO) { } else if (ftdmchan->type == FTDM_CHAN_TYPE_FXO) {
event_id = FTDM_OOB_RING_START; event_id = FTDM_OOB_RING_START;
@ -1076,7 +1077,7 @@ FIO_CHANNEL_NEXT_EVENT_FUNCTION(zt_channel_next_event)
break; break;
default: default:
{ {
ftdm_log(FTDM_LOG_WARNING, "Unhandled event %d for %d:%d\n", zt_event_id, span->span_id, i); ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Unhandled event %d for %d:%d\n", zt_event_id, span->span_id, i);
event_id = FTDM_OOB_INVALID; event_id = FTDM_OOB_INVALID;
} }
break; break;