op_prg_list_init()
摘要
初始化一个已由用户代码分配的现有列表。
注意: 该内核过程是一个仅为向后兼容而保留的宏调用。新代码应使用 prg_list_init()。
语法
op_prg_list_init (list_ptr)
| 参数 | 类型 | 说明 |
|---|---|---|
list_ptr |
List* |
指向目标列表的指针 [列表指针可以从多个内核过程获得:空列表可由 op_prg_list_create() 获得;表示文件内容的列表可由 op_prg_gdf_read() 获得;列表可由用户代码分配并通过 op_prg_list_init() 初始化。] |
返回类型
void
无返回值。
示例
/* allocate a list */
list_ptr = (List *) op_prg_mem_alloc (sizeof (List));
/* initialize a list */
op_prg_list_init (list_ptr);
/** move the contents of subqueue #0 into the list **/
/* determine the number of packets in the subqueue */
subq_size = op_subq_stat (0, OPC_QSTAT_PKSIZE);
for (i = 0; i < subq_size; i++)
{
/* take a single packet from the subqueue head */
pkptr = op_subq_pk_remove (0, OPC_QPOS_HEAD);
/* insert the packet onto the list tail */
op_prg_list_insert (list_ptr, pkptr, OPC_LISTPOS_TAIL);
}
详情
该内核过程在列表数据结构中设置初始值,使其处于空状态。该内核过程必须应用于用户代码分配的列表(即不是从内核过程 op_prg_list_create() 获得的列表指针),然后才能对其应用其他 op_prg_list… 内核过程。
注意: 该内核过程不是 MT 安全的,如 “Multi-Threading Safety“ 第 11 页所述。对共享列表的访问必须由外部串行化。
用途
提供一种机制,用于准备一个完全全新的、由用户代码分配的列表(可以来自静态分配的变量,或位于动态分配的数据结构内)。这是获得空列表的两种方法之一;另一种方法是让仿真内核通过内核过程 op_prg_list_create() 动态分配一个列表。
错误
- 程序中止:段错误(由于列表指针非法或列表格式错误)。
参考
- 使用内核过程 op_prg_list_create() 让仿真内核分配一个新的空列表
- 使用内核过程 op_prg_list_insert() 向列表中插入元素
- 使用内核过程 op_prg_list_free() 移除并释放列表上的所有元素(保留列表本身)
- 使用内核过程 op_prg_mem_free() 释放不再有用的列表(在其元素已被释放之后)