⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netbuflib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
* Assuming you have set up the configuration tables as shown above, a * typical call to netPoolInit() would be as follows:* .CS*     int clDescTblNumEnt = (NELEMENTS(clDescTbl));*     NET_POOL 	netPool;*     NET_POOL_ID 	pNetPool = &netPool;**     if (netPoolInit (pNetPool, &mClBlkConfig, &clDescTbl [0], clDescTblNumEnt,*         NULL) != OK)*         return (ERROR);*.CE** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, access to the contents of a memory pool is limited to * the protection domain within which you made the netPoolInit() call that * created the pool.  In addition, all parameters to a netPoolInit() call * must be valid within the protection domain from which you make the call. * This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS: OK or ERROR.** ERRNO:*  S_netBufLib_MEMSIZE_INVALID*  S_netBufLib_CLSIZE_INVALID*  S_netBufLib_NO_SYSTEM_MEMORY*  S_netBufLib_MEM_UNALIGNED*  S_netBufLib_MEMSIZE_UNALIGNED*  S_netBufLib_MEMAREA_INVALID** SEE ALSO: netPoolDelete()*/STATUS netPoolInit    (    NET_POOL_ID		pNetPool,	 /* pointer to a net pool */    M_CL_CONFIG *	pMclBlkConfig,	 /* pointer to a mBlk configuration */    CL_DESC *		pClDescTbl,	 /* pointer to cluster desc table */    int			clDescTblNumEnt, /* number of cluster desc entries */    POOL_FUNC *		pFuncTbl	 /* pointer to pool function table */    )    {    if (pNetPool == NULL)        return (ERROR);    if (pFuncTbl != NULL)        pNetPool->pFuncTbl = pFuncTbl;    else        pNetPool->pFuncTbl = _pNetPoolFuncTbl;	/* default func table */    return (poolInit (pNetPool, pMclBlkConfig, pClDescTbl,        clDescTblNumEnt, FROM_HOMEPDHEAP)); /* allocate from the homePD's heap */    }/********************************************************************************* netPoolKheapInit - kernel heap version of netPoolInit()* * This initializes a netBufLib-managed memory pool from Kernel heap.* See netPoolInit() for more detail.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS: OK or ERROR.** ERRNO:*  N/A** SEE ALSO: netPoolInit(), netPoolDelete()*/STATUS netPoolKheapInit    (    NET_POOL_ID		pNetPool,	 /* pointer to a net pool */    M_CL_CONFIG *	pMclBlkConfig,	 /* pointer to a mBlk configuration */    CL_DESC *		pClDescTbl,	 /* pointer to cluster desc table */    int			clDescTblNumEnt, /* number of cluster desc entries */    POOL_FUNC *		pFuncTbl	 /* pointer to pool function table */    )    {    if (pNetPool == NULL)        return (ERROR);    if (pFuncTbl != NULL)        pNetPool->pFuncTbl = pFuncTbl;    else        pNetPool->pFuncTbl = _pNetPoolFuncTbl;	/* default func table */    return (poolInit (pNetPool, pMclBlkConfig, pClDescTbl,        clDescTblNumEnt, FROM_KHEAP)); /* allocate from kernel heap */    }/********************************************************************************* netPoolDelete - delete a memory pool** This routine deletes the specified netBufLib-managed memory pool.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS: OK or ERROR.** ERRNO:*  S_netBufLib_NETPOOL_INVALID*/STATUS netPoolDelete    (    NET_POOL_ID		pNetPool	/* pointer to a net pool */    )    {    int			ix;		/* index variable */    int			iy;		/* index variable */    CL_POOL_ID		pClPool;	/* pointer to the pool */    if (pNetPool->pPoolStat == NULL)        {        errno = S_netBufLib_NETPOOL_INVALID;        return (ERROR);			/* pool already deleted */        }    free (pNetPool->pPoolStat);    for (ix = 0; ix < CL_TBL_SIZE; ix++)        {        pClPool = pNetPool->clTbl [ix];        if (pClPool != NULL)            {            for (iy = ix + 1; iy < CL_TBL_SIZE; iy++)                {                if (pClPool == pNetPool->clTbl [iy])                    pNetPool->clTbl [iy] = NULL;                }            free (pClPool);            }        }    bzero ((char *)pNetPool, sizeof(NET_POOL));	/* zero the structure */    return (OK);    }/********************************************************************************* netMblkFree - free an `mBlk' back to its memory pool** This routine frees the specified `mBlk' back to the specified memory pool.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS: N/A*/void netMblkFree    (    NET_POOL_ID		pNetPool,	/* pointer to the net pool */    M_BLK_ID	 	pMblk		/* mBlk to free */    )    {    if (pNetPool == NULL || pNetPool->pFuncTbl == NULL ||        pNetPool->pFuncTbl->pMblkFreeRtn == NULL)        return;    (*pNetPool->pFuncTbl->pMblkFreeRtn) (pNetPool, pMblk);    }/********************************************************************************* netClBlkFree - free a `clBlk'-cluster construct back to the memory pool** This routine decrements the reference counter in the specified `clBlk'. * If the reference count falls to zero, this routine frees both the `clBlk'* and its associated cluster back to the specified memory pool.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS: N/A*/void netClBlkFree    (    NET_POOL_ID		pNetPool,	/* pointer to the net pool */    CL_BLK_ID	 	pClBlk		/* pointer to the clBlk to free */    )    {    pNetPool 		= pClBlk->pNetPool;        if (pNetPool == NULL || pNetPool->pFuncTbl == NULL ||        pNetPool->pFuncTbl->pClBlkFreeRtn == NULL)        return;    (*pNetPool->pFuncTbl->pClBlkFreeRtn) (pClBlk);    }/********************************************************************************* netClFree - free a cluster back to the memory pool** This routine returns the specified cluster buffer back to the specified* memory pool.  * * VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS: N/A*/void netClFree    (    NET_POOL_ID		pNetPool,	/* pointer to the net pool */    UCHAR * 		pClBuf		/* pointer to the cluster buffer */    )    {    if (pNetPool == NULL || pNetPool->pFuncTbl == NULL ||        pNetPool->pFuncTbl->pClFreeRtn == NULL)        return;    (*pNetPool->pFuncTbl->pClFreeRtn) (pNetPool, pClBuf);    }/********************************************************************************* netMblkClFree - free an `mBlk'-`clBlk'-cluster construct** For the specified `mBlk'-`clBlk'-cluster construct, this routine* frees the `mBlk' back to the specified memory pool.  It also decrements * the reference count in the `clBlk' structure.  If the reference count * falls to zero, no other `mBlk' structure reference this `clBlk'.  In that * case, this routine also frees the `clBlk' structure and its associated * cluster back to the specified memory pool.  ** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * Likewise, the returned ID is valid in the kernel protection domain only.* This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS* If the specified `mBlk' was part of an `mBlk' chain, this routine returns * a pointer to the next `mBlk'.  Otherwise, it returns a NULL.** ERRNO:*  S_netBufLib_MBLK_INVALID*/M_BLK_ID netMblkClFree    (    M_BLK_ID 		pMblk		/* pointer to the mBlk */    )    {    NET_POOL_ID 	pNetPool;    if (pMblk == NULL)        return (NULL);    pNetPool = MBLK_TO_NET_POOL(pMblk);    return ((*pNetPool->pFuncTbl->pMblkClFreeRtn) (pNetPool, pMblk));    }/********************************************************************************* netMblkClChainFree - free a chain of `mBlk'-`clBlk'-cluster constructs** For the specified chain of `mBlk'-`clBlk'-cluster constructs, this * routine frees all the `mBlk' structures back to the specified memory pool.  * It also decrements the reference count in all the `clBlk' structures.  If * the reference count in a `clBlk' falls to zero, this routine also frees * that `clBlk' and its associated cluster back to the specified memory pool. ** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS: N/A** ERRNO:*  S_netBufLib_MBLK_INVALID*/void netMblkClChainFree    (    M_BLK_ID 		pMblk		/* pointer to the mBlk */    )    {    NET_POOL_ID 	pNetPool;    while (pMblk != NULL)        {        pNetPool = MBLK_TO_NET_POOL(pMblk);        pMblk 	 = (*pNetPool->pFuncTbl->pMblkClFreeRtn) (pNetPool, pMblk);        }    }/********************************************************************************* netMblkGet - get an `mBlk' from a memory pool** This routine allocates an `mBlk' from the specified memory pool, if* available.** .IP <pNetPool> 9* Expects a pointer to the pool from which you want an `mBlk'.* .IP <canWait>* Expects either M_WAIT or M_DONTWAIT.  If no 'mBlk' is immediately available,* the M_WAIT value allows this routine to repeat the allocation attempt after* performing garbage collection. It omits these steps when the M_DONTWAIT* value is used.* .IP <type>* Expects the type value that you want to associate with the returned `mBlk'.* .LP** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * Likewise, the returned ID is valid in the kernel protection domain only.* This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS* M_BLK_ID or NULL if no `mBlk' is available.** ERRNO:*  S_netBufLib_MBLK_INVALID*/M_BLK_ID netMblkGet    (    NET_POOL_ID		pNetPool,	/* pointer to the net pool */    int			canWait,	/* M_WAIT/M_DONTWAIT */    UCHAR		type		/* mBlk type */    )    {    if (pNetPool == NULL || pNetPool->pFuncTbl == NULL ||        pNetPool->pFuncTbl->pMblkGetRtn == NULL)        return (NULL);    return ((*pNetPool->pFuncTbl->pMblkGetRtn) (pNetPool, canWait, type));    }/********************************************************************************* netClBlkGet - get a `clBlk'** This routine gets a `clBlk' from the specified memory pool.* .IP <pNetPool> 9* Expects a pointer to the pool from which you want a `clBlk'.* .IP <canWait>* Expects either M_WAIT or M_DONTWAIT.  If no 'clBlk' is immediately available,* the M_WAIT value allows this routine to repeat the allocation attempt after* performing garbage collection. It omits these steps when the M_DONTWAIT* value is used.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * Likewise, the returned ID is valid in the kernel protection domain only.* This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS: CL_BLK_ID or a NULL if no `clBlk' was available.*/CL_BLK_ID netClBlkGet    (    NET_POOL_ID		pNetPool,	/* pointer to the net pool */    int			canWait		/* M_WAIT/M_DONTWAIT */    )    {    if (pNetPool == NULL || pNetPool->pFuncTbl == NULL ||        pNetPool->pFuncTbl->pClBlkGetRtn == NULL)        return (NULL);    return ((*pNetPool->pFuncTbl->pClBlkGetRtn) (pNetPool, canWait));    }/********************************************************************************* netClusterGet - get a cluster from the specified cluster pool** This routine gets a cluster from the specified cluster pool <pClPool> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -