FreeTDM: Add span start/stop callbacks to ftdm_io_interface.

Callbacks are invoked from ftdm_span_start/_stop().
I/O is started before SIG and shut down in reverse order.

This is needed for ftmod_misdn, to move the mISDN message handling
into a separate thread (solving the mISDN socket vs. FreeTDM API issues).

With these callbacks, the I/O thread can be started after the span I/O configuration
has been (successfully) completed and stopped before destroying the span.

NOTE: Both SIG and I/O callbacks are called with the span mutex locked,
so threads created or destroyed synchronously in either of the custom
start/stop functions, can not use ftdm_span_*() functions that lock
the span mutex (e.g. ftdm_span_get_channel_count()).

Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
This commit is contained in:
Stefan Knoblich
2012-08-15 13:19:38 +02:00
parent 431f7dd6bf
commit 548222f9f3
2 changed files with 22 additions and 1 deletions

View File

@@ -760,11 +760,16 @@ FT_DECLARE(ftdm_status_t) ftdm_span_stop(ftdm_span_t *span)
goto done;
}
/* Stop SIG */
status = span->stop(span);
if (FTDM_SUCCESS == status) {
if (status == FTDM_SUCCESS) {
ftdm_clear_flag(span, FTDM_SPAN_STARTED);
}
/* Stop I/O */
if (span->fio && span->fio->span_stop) {
status = span->fio->span_stop(span);
}
done:
ftdm_mutex_unlock(span->mutex);
@@ -5309,6 +5314,14 @@ FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span)
goto done;
}
/* Start I/O */
if (span->fio && span->fio->span_start) {
status = span->fio->span_start(span);
if (status != FTDM_SUCCESS)
goto done;
}
/* Start SIG */
status = ftdm_report_initial_channels_alarms(span);
if (status != FTDM_SUCCESS) {
goto done;