op_ev_cancel_if_pending()

摘要

撤销先前已计划的事件,撤销前先确认该事件处于挂起状态。

语法

op_ev_cancel_if_pending (evhandle)
参数 类型 说明
evhandle Evhandle 标识待取消事件的事件句柄
事件句柄可以从本包中的多个内核过程获取,例如 op_ev_seek_time() 和 op_ev_next(),以及 op_intrpt_schedule_self() 等其他内核过程。

返回类型

Compcode

若事件被成功取消则返回 OPC_COMPCODE_SUCCESS;若事件无效或无法取消则返回 OPC_COMPCODE_FAILURE。

示例

/* Obtain the currently executing event (it must be at this module, */
/* since this module woke up.) and the one after it. */
this_event = op_ev_current ();
next_event = op_ev_next_local (this_event);

/* Loop through all of the events scheduled for this module */
/* and cancel any that are retransmission timers. */
while (op_ev_valid (next_event))
	{
	if ((op_ev_type (next_event) == OPC_INTRPT_SELF) &&
		(op_ev_code (next_event) == RETRANS_TIMER))
		{
		retrans_timer = next_event;
		next_event = op_ev_next_local (retrans_timer);
		op_ev_cancel_if_pending (retrans_timer);
		}
	else
		/* Obtain the next event; if there are no more events, op_ev_next_local () */
		/* will return an invalid event handle and the loop will terminate. */
		next_event = op_ev_next_local (next_event);
	}

详情

该内核过程首先确认 evhandle 所指向的事件处于挂起状态,然后尝试取消该事件。如果事件不是当前事件但仍然处于计划状态,则该事件是挂起的。即使事件处于挂起状态,如果另一个线程同时占用了该事件,取消也可能失败。如果事件被取消且它原本是流中断,则与该事件关联的数据包将被销毁。

用途

提供了一种撤销不再必要或不再需要的事件的机制。该内核过程的工作方式与 op_ev_cancel() 相同,不同之处在于它会在取消事件之前先确认事件处于挂起状态。该内核过程适用于多线程环境:在这种环境下,如下建模写法:

if (op_ev_valid (evh))
	{
	op_ev_cancel (evh);
	}

如果在两次函数调用之间另一个线程开始执行该事件,则可能失败。

错误

  • 程序中止:段错误。(由于格式错误的事件句柄)
  • 可恢复错误:事件句柄指向的事件无效或当前未被计划。
  • 可恢复错误:当前事件(<schedule_id>)不能被取消。
  • 可恢复错误:正在执行的事件(<schedule_id>)不能被取消。
  • 可恢复错误:无法取消未定位的事件(<schedule_id>)。

参考

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com