in src/channel_internal.c [269:323]
static void cancel_op(void* context)
{
CHANNEL_OP* channel_op = context;
CHANNEL_INTERNAL* channel_internal_ptr = THANDLE_GET_T(CHANNEL_INTERNAL)(channel_op->channel_internal);
bool call_callback = false;
/*Codes_SRS_CHANNEL_INTERNAL_43_154: [ cancel_op shall call sm_exec_begin. ]*/
SM_RESULT sm_result = sm_exec_begin(channel_internal_ptr->sm);
if (sm_result != SM_EXEC_GRANTED)
{
/*Codes_SRS_CHANNEL_INTERNAL_43_155: [ If there are any failures, cancel_op shall fail. ]*/
LogError("Failure in sm_exec_begin(channel_internal_ptr->sm=%p). SM_RESULT sm_result = %" PRI_MU_ENUM "", channel_internal_ptr->sm, MU_ENUM_VALUE(SM_RESULT, sm_result));
}
else
{
/*Codes_SRS_CHANNEL_INTERNAL_43_134: [ cancel_op shall call srw_lock_acquire_exclusive. ]*/
srw_lock_acquire_exclusive(channel_internal_ptr->lock);
{
/*Codes_SRS_CHANNEL_INTERNAL_43_135: [ If the operation is in the list of pending operations, cancel_op shall call DList_RemoveEntryList to remove it. ]*/
if (
(channel_op->anchor.Flink != &channel_op->anchor) &&
(&channel_op->anchor == channel_op->anchor.Flink->Blink)
)
{
(void)DList_RemoveEntryList(&channel_op->anchor);
call_callback = true;
}
/*Codes_SRS_CHANNEL_INTERNAL_43_139: [ cancel_op shall call srw_lock_release_exclusive. ]*/
srw_lock_release_exclusive(channel_internal_ptr->lock);
}
/*Codes_SRS_CHANNEL_INTERNAL_43_136: [ If the result of the operation is CHANNEL_CALLBACK_RESULT_OK, cancel_op shall set it to CHANNEL_CALLBACK_RESULT_CANCELLED. ]*/
if (channel_op->result == CHANNEL_CALLBACK_RESULT_OK)
{
channel_op->result = CHANNEL_CALLBACK_RESULT_CANCELLED;
}
/*Codes_SRS_CHANNEL_INTERNAL_43_138: [ If the operation had been found in the list of pending operations, cancel_op shall call threadpool_schedule_work with execute_callbacks as work_function and the operation as work_function_context. ]*/
if (call_callback)
{
if (threadpool_schedule_work(channel_internal_ptr->threadpool, execute_callbacks, channel_op) != 0)
{
LogError("Failure in threadpool_schedule_work(channel_internal_ptr->threadpool=%p, execute_callbacks=%p, channel_op=%p)", channel_internal_ptr->threadpool, execute_callbacks, channel_op);
}
else
{
/* all ok */
}
}
/*Codes_SRS_CHANNEL_INTERNAL_43_156: [ cancel_op shall call sm_exec_end. ]*/
sm_exec_end(channel_internal_ptr->sm);
}
}