op_subq_empty()
摘要
判断指定子队列中是否没有数据包。
语法
op_subq_empty (subq_index)
| 参数 | 类型 | 说明 |
|---|---|---|
subq_index |
int |
目标子队列的数字索引 [子队列流索引从 0 开始,依次递增 1。子队列的数量没有上限,但如果连续使用它们,可以实现内存的节约使用。除了显式的子队列索引,还可以指定抽象子队列选择索引。抽象子队列选择索引通过某个子队列独有的属性来指定该子队列。可接受的抽象子队列选择索引列于表 85“Subqueue Selection Index Symbolic Constants“ 第 26 页。] |
返回类型
Boolean
指示指定子队列是否为空的 Boolean 值。若指定子队列为空,返回值为 OPC_TRUE;否则为 OPC_FALSE。
示例
摘自:示例模型(models/std/base);进程模型(pf_fifo);状态(SEND_HEAD);enter execs。
/* a request has been made to forward a packet */
/* over one of the queue’s output streams */
/* the packet will be pulled from the subqueue */
/* with the same index as the output stream */
/* determine which subqueue is being accessed */
subq_index = op_intrpt_code ();
/* check if it is empty */
if (op_subq_empty (subq_index) == OPC_FALSE)
{
/* access the first packet in the subqueue */
pkptr = op_subq_pk_remove (subq_index, OPC_QPOS_HEAD);
/* forward it to the destination over requested stream */
/* use ’quiet’ mode to avoid causing a stream interrupt. */
op_pk_send_quiet (pkptr, subq_index);
}
详情
本 KP 只能在与队列模块上运行的进程的上下文中调用(或由队列进程直接或间接调用的函数中调用);从处理器上运行的进程或管道级调用它们将导致错误。
子队列初始时为空。数据包通过 KP op_subq_pk_insert() 加入子队列,并通过 KP op_subq_pk_remove()、op_subq_flush() 或 op_q_flush() 从中移除。
用途
提供一种判断子队列是否为空的机制。本 KP 通常作为进程 FSM 中的条件,或 if 语句的条件子句,用于括起一组仅在某个特定子队列包含数据包时才应执行的语句。通常,被括起的语句会尝试处理子队列中的一个或多个数据包,并通过 KP op_subq_pk_remove() 将其移除。
错误
- 程序中止:KP 需要队列上下文。
- 可恢复错误:子队列选择标志(
<flag>)无法识别。
参考
- 使用 KP op_q_empty() 判断外围队列中的所有子队列是否均为空
- 使用 KP op_subq_stat(),以
OPC_QSTAT_PKSIZE符号常量作为参数,判断子队列中包含的数据包数量 - 使用 KP op_subq_pk_remove() 从子队列移除一个数据包,并获取其指针
- 使用 KP op_subq_flush() 移除子队列中的所有数据包