ill_core.c
来自「澳洲人写的Cortex,包括uC_IP协议栈」· C语言 代码 · 共 1,267 行 · 第 1/4 页
C
1,267 行
<HTML><HEAD><TITLE>/home/asysweb/public_html/cortex/kernel/src/ill_core.c</TITLE></HEAD><BODY><pre><font color="#6920ac">/*************************************************************************/</font><font color="#6920ac">/* */</font><font color="#6920ac">/* Copyright (c) 1997-1999 Australian Real Time Embedded Systems */</font><font color="#6920ac">/* */</font><font color="#6920ac">/* PROPRIETARY RIGHTS of Australian Real Time Embedded Systems */</font><font color="#6920ac">/* are involved in the subject matter of this material. All reproduction,*/</font><font color="#6920ac">/* manufacturing, use, and sales rights pertaining to this subject matter*/</font><font color="#6920ac">/* are governed by the license agreement. The recipient of this software */</font><font color="#6920ac">/* implicitly accepts the terms of the license. */</font><font color="#6920ac">/* */</font><font color="#6920ac">/*************************************************************************/</font><font color="#6920ac">/************************************************************************** * * FILE NAME * * ill_core.c * * SYSTEM COMPONENT * * Index Linked List Management Component * * DESCRIPTION * * This file contains the core services for The Index Linked List * Management Component. * * SERVICES * * ilst_CreatePool * ilst_AllocateList * ilst_IsEmpty * ilst_AddHead * ilst_RemoveTail * ilst_Enqueue * ilst_Dequeue * * SCCS HISTORY * * @(#)ill_core.c 1.8, 01/25/99, 00:30:28 * * AUTHOR * * Vadim N. Azarovsky * * CREATED * * 28-Jan-1997 by Vadim N. Azarovsky * * REVISION HISTORY * * NAME DATE REMARKS * **************************************************************************/</font><b><font color='DarkGreen'>#include</font></b> <a href="ill_priv.h.FIND-INC"><font color="blue">"ill_priv.h"</font></a><b><font color='DarkGreen'>#include</font></b> <a href="ass_defs.h.FIND-INC"><font color="blue">"ass_defs.h"</font></a><b><font color='DarkGreen'>#include</font></b> <a href="seg_defs.h.FIND-INC"><font color="blue">"seg_defs.h"</font></a><font color="#6920ac">/************************************************************************** * * SERVICE NAME * * ilst_CreatePool * * SYNOPSIS * * #include "cortex.h" * ilst_Pool_t Pool; * ilst_Node_t NodesTable[100+3*2]; * ilst_CreatePool(&Pool, NodesTable, 100, 3, NULL); * * DESCRIPTION * * Create the pool of the index linked lists. * * ARGUMENTS * * o Pointer to the pool control block. If NULL control block * will be allocated; * o Poiner to the nodes table. The table shall be large enough to * accomodate specified number of list nodes and head/tail nodes. * To calculare number of required nodes use the following formula: * * TableNodes = NrNodes_a + (NrLists_a * 2) * * If this parameter is NULL table will be dynamicaly allocated; * o Number of nodes; * o Number of lists can be allocated from the pool; * o Attribute values. If NULL than default attribute values * will be used; Attribute specifies memory segment to use if * dynamic memory allocation required; * * RETURN VALUE * * Pointer to pool control block or NULL if memory allocation error * detected. * * USAGE * * o Used by CORTEX to create internal control structures; * o Application level; * * CONSTRAINS * * Does not provide multi-thread access protection. * * AUTOR * * Vadim N. Azarovsky * * REVISION HISTORY * * NAME DATE REMARKS * VA 28-Jan-1997 Created initial version * **************************************************************************/</font><font size="+1"><i>ilst_Pool_t</i> *<b><font color="azure1"><a name="ilst_CreatePool">ilst_CreatePool</a></font></b>( <i>ilst_Pool_t</i> *pPool_a, <font color="#6920ac">/* pool control block */</font> <i>ilst_Node_t</i> *pTable_a, <font color="#6920ac">/* node table */</font> <i>crtx_Int_t</i> NrNodes_a, <font color="#6920ac">/* number of nodes */</font> <i>crtx_Int_t</i> NrLists_a, <font color="#6920ac">/* number of lists */</font> <i>ilst_Attr_t</i> *pAttr_a <font color="#6920ac">/* attribute values */</font>){</font><font color="#6920ac">/********************* * LOCAL VARIABLES * *********************/</font> <font color="#6920ac">/* None */</font><font color="#6920ac">/********************* * PROCEDURE LOGIC * *********************/</font> <font color="#6920ac">/* Validate Arguments */</font> <a href="CRTX_ASSERT.FIND-DEF">CRTX_ASSERT</a>(NrNodes_a > 0) <a href="CRTX_ASSERT.FIND-DEF">CRTX_ASSERT</a>(NrLists_a > 0) <font color="#6920ac">/* Prepare attribute argument */</font> <b>if</b> (pAttr_a == <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a>) { <font color="#6920ac">/* use default attributes */</font> pAttr_a = &ilst_AttrDefault_g; } <font color="#6920ac">/* Prepare pool control block */</font> <b>if</b> (pPool_a == <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a>) { <font color="#6920ac">/* allocate pool control block */</font> pPool_a = (<i>ilst_Pool_t</i>*)<a href="dmem_Alloc.FIND-FUNC">dmem_Alloc</a>(pAttr_a->Segment, <i>sizeof</i>(<i>ilst_Pool_t</i>), <i>sizeof</i>(<i>crtx_Unsigned_t</i>)); <b>if</b> ((<i>crtx_Void_t</i>*)pPool_a == (<i>crtx_Void_t</i>*)<a href="DMEM_ILLEGAL.FIND-DEF">DMEM_ILLEGAL</a>) { <font color="#6920ac">/* memory allocation error */</font> <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> MemDescAllocError_Exc; } <font color="#6920ac">/* mark as internally allocated pool control block */</font> pPool_a->Flags = <a href="ILST_FLAG_INIT.FIND-DEF">ILST_FLAG_INIT</a> | <a href="ILST_FLAG_POOL_ALLOC.FIND-DEF">ILST_FLAG_POOL_ALLOC</a>; } <b>else</b> { <font color="#6920ac">/* mark as externally allocated pool control block */</font> pPool_a->Flags = <a href="ILST_FLAG_INIT.FIND-DEF">ILST_FLAG_INIT</a>; } <font color="#6920ac">/* Prepare nodes table */</font> <b>if</b> (pTable_a == <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a>) { <font color="#6920ac">/* allocate nodes */</font> pTable_a = (<i>ilst_Node_t</i>*)<a href="dmem_Alloc.FIND-FUNC">dmem_Alloc</a>(pAttr_a->Segment, (NrNodes_a+(NrLists_a*2))*<i>sizeof</i>(<i>ilst_Node_t</i>), <i>sizeof</i>(<i>crtx_Unsigned_t</i>)); <b>if</b> ((<i>crtx_Void_t</i>*)pTable_a == (<i>crtx_Void_t</i>*)<a href="DMEM_ILLEGAL.FIND-DEF">DMEM_ILLEGAL</a>) { <font color="#6920ac">/* memory allocation error */</font> <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> MemTableAllocError_Exc; } <font color="#6920ac">/* mark as internally allocated node table */</font> pPool_a->Flags |= <a href="ILST_FLAG_TABLE_ALLOC.FIND-DEF">ILST_FLAG_TABLE_ALLOC</a>; }<b><font color='DarkGreen'>#if</font></b><font color="maroon"> ENVI_CRTX_ERR_CHECK_LEVEL > 0</font> <font color="#6920ac">/* initialise node table */</font> { <i>crtx_Int_t</i> i; <i>ilst_Node_t</i> *pNode = pTable_a; <b>for</b> (i=0; i<NrNodes_a+(NrLists_a*2); i++) { <a href="ILST_SET_NODE_ID.FIND-DEF">ILST_SET_NODE_ID</a>(pNode); pNode->pPool = pPool_a; pNode->Next = pNode->Prev = <a href="ILST_INVALID_INDEX.FIND-DEF">ILST_INVALID_INDEX</a>; pNode++; } }<b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* ENVI_CRTX_ERR_CHECK_LEVEL > 0 */</font></font> <font color="#6920ac">/* initialise pool control block */</font> pPool_a->pTable = pTable_a; pPool_a->NrNodes = NrNodes_a; pPool_a->NrLists = NrLists_a; pPool_a->NextList = 0; pPool_a->Attr = *pAttr_a;<b><font color='DarkGreen'>#if</font></b><font color="maroon"> ENVI_CRTX_ERR_CHECK_LEVEL > 0</font> <a href="ILST_SET_POOL_ID.FIND-DEF">ILST_SET_POOL_ID</a>(pPool_a);<b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* ENVI_CRTX_ERR_CHECK_LEVEL > 0 */</font></font> <b>return</b> pPool_a;<font color="#6920ac">/************************ * EXCEPTION HANDLING * ************************/</font><font color="blue">MemTableAllocError_Exc:</font> <font color="#6920ac">/* memory allocation error exception */</font> <b>if</b>(pPool_a->Flags & <a href="ILST_FLAG_POOL_ALLOC.FIND-DEF">ILST_FLAG_POOL_ALLOC</a>) { <font color="#6920ac">/* release internaly allocated pool control block */</font> <a href="dmem_Free.FIND-FUNC">dmem_Free</a>(pPool_a->Attr.Segment, (<i>crtx_Void_t</i>*)pPool_a, <i>sizeof</i>(<i>ilst_Pool_t</i>)); } <font color="#6920ac">/* FALL-THROUGH */</font><font color="blue">MemDescAllocError_Exc:</font> <font color="#6920ac">/* memory allocation error exception */</font> <b>return</b> <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a>;}<font color="#6920ac">/************************************************************************** * * SERVICE NAME * * ilst_DestroyPool * * SYNOPSIS * * #include "cortex.h" * ilst_Pool_t *pPool; * pPool = ilst_CreatePool(NULL, NULL, NrNodes, NrLists, NULL); * ... * ilst_DestroyPool(pPool); * * DESCRIPTION * * Destory pool of the index linked lists created by ilst_CreatePool(). * * ARGUMENTS * * o Pointer to the pool control block. * * RETURN VALUE * * None * * USAGE * * o Used by CORTEX to create internal control structures; * o Application level; * * CONSTRAINS * * Does not provide multi-thread access protection. Accessing destroyed * pool is undetected run-time error. * * AUTOR * * Vadim N. Azarovsky * * REVISION HISTORY * * NAME DATE REMARKS * VA 28-Jan-1997 Created initial version * **************************************************************************/</font><font size="+1"><i>crtx_Void_t</i> <b><font color="azure1"><a name="ilst_DestroyPool">ilst_DestroyPool</a></font></b>( <i>ilst_Pool_t</i> *pPool_a){</font><font color="#6920ac">/********************* * LOCAL VARIABLES * *********************/</font> <font color="#6920ac">/* None */</font><font color="#6920ac">/********************* * PROCEDURE LOGIC * *********************/</font> <a href="CRTX_ASSERT.FIND-DEF">CRTX_ASSERT</a>(pPool_a) <b>if</b>(pPool_a->Flags & <a href="ILST_FLAG_TABLE_ALLOC.FIND-DEF">ILST_FLAG_TABLE_ALLOC</a>) { <font color="#6920ac">/* release internaly allocated nodes table */</font> <a href="dmem_Free.FIND-FUNC">dmem_Free</a>(pPool_a->Attr.Segment, (<i>crtx_Void_t</i>*)pPool_a->pTable, (pPool_a->NrNodes+(pPool_a->NrLists*2))* <i>sizeof</i>(<i>ilst_Node_t</i>)); }<b><font color='DarkGreen'>#if</font></b><font color="maroon"> ENVI_CRTX_ERR_CHECK_LEVEL > 0</font> <b>else</b> { <font color="#6920ac">/* initialise node table */</font> <i>crtx_Int_t</i> i; <i>ilst_Node_t</i> *pNode = pPool_a->pTable; <b>for</b> (i=0; i<pPool_a->NrNodes+(pPool_a->NrLists*2); i++) { <a href="ILST_SET_NODE_ID.FIND-DEF">ILST_SET_NODE_ID</a>(pNode); pNode->pPool = pPool_a; pNode->Next = pNode->Prev = <a href="ILST_INVALID_INDEX.FIND-DEF">ILST_INVALID_INDEX</a>; pNode++; } }<b><font color='DarkGreen'>#endif</font></b><font color="maroon"> <font color="#6920ac">/* ENVI_CRTX_ERR_CHECK_LEVEL > 0 */</font></font> <b>if</b>(pPool_a->Flags & <a href="ILST_FLAG_POOL_ALLOC.FIND-DEF">ILST_FLAG_POOL_ALLOC</a>) { <font color="#6920ac">/* release internaly allocated pool control block */</font> <a href="dmem_Free.FIND-FUNC">dmem_Free</a>(pPool_a->Attr.Segment, (<i>crtx_Void_t</i>*)pPool_a,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?