/**
* \brief Handler for channel state change
* \param ftdmchan Channel to handle
+ * \note This function MUST be called with the channel locked
*/
static __inline__ void state_advance(ftdm_channel_t *chan)
{
if (!chan) {
ftdm_log(FTDM_LOG_ERROR, "-- Unable to get channel %d:%d\n", ftdm_span_get_id(span), pevent->ring.channel);
- goto done;
+ return ret;
+ }
+
+ ftdm_channel_lock(chan);
+
+ if (chan->call_data) {
+ /* we could drop the incoming call, but most likely the pointer is just a ghost of the past,
+ * this check is just to detect potentially unreleased pointers */
+ ftdm_log_chan(chan, FTDM_LOG_ERROR, "channel already has call %p!\n", chan->call_data);
+ chan->call_data = NULL;
}
if (ftdm_channel_get_state(chan) != FTDM_CHANNEL_STATE_DOWN || ftdm_test_flag(chan, FTDM_CHANNEL_INUSE)) {
/* hurr, this is valid as along as nobody releases the call */
chan->call_data = pevent->ring.call;
- ftdm_set_state_locked(chan, FTDM_CHANNEL_STATE_RING);
+ ftdm_set_state(chan, FTDM_CHANNEL_STATE_RING);
done:
+ ftdm_channel_unlock(chan);
return ret;
}