工作总结-----资源池

 

#define DRV_L3_U32BIT_OFFSET      (5)    /* 一个UINT32类型包含BIT的个数,移位方式表示 */

#define DRV_L3_U8BIT_OFFSET      (3)       /* 一个UCHAR类型包含BIT的个数,移位方式表示 */

#define DRV_L3_BMP_RSC_IDLE_BIT  (256)

#define DRV_L3_BMP_RSC_MNG_LEN  (256)   / * 此处管理bitmap的个数,一个UCHAR的计数范围,必须被4整除 * /  

#define DRV_L3_BMP_RSC_TO_MNG (idx)   ((idx) >> 8)

#define DRV_L3_BMP_MNG_TO_RSC (mng)  ((idx) << 8)

#define DRV_L3_BMP_RSC_MNG_CNT (poolLen)       ((UINT32) (( (poolLen) + (DRV_L3_BMP_RSC_MNG_LEN - 1)))  /  DRV_L3_BMP_RSC_MNG_LEN)

#define DRV_L3_BIT_SET(aucBmp, usPos)    ( (aucBmp)[(usPos) >> DRV_L3_U8BIT_OFFSET]   |= (UCHAR) ( (1 << ((usPos) & 0x7))))))

#define DRV_L3_BIT_CLEAR(aucBmp, usPos)    ( (aucBmp)[(usPos) >> DRV_L3_U8BIT_OFFSET]  &= (UCHAR) (~((UCHAR) (1 << ((usPos) & 0x7))))))

#define DRV_L3_BIT_TEST(aucBmp, usPos)    ( (aucBmp)[(usPos) >> DRV_L3_U8BIT_OFFSET]   &  (UCHAR) ( (1 << ((usPos) & 0x7))))))

 

 

 

 

 

 

 

typedef struct tagDRV_L3_BITMAPRESOURCE_POOL

{

  UINT32 *puiMngBmp;         / * 管理资源组的BitMap信息* /

  UINT32* puiRscBmp;          / * 资源状态位图数组 * /

  UINT32 uiMngBmpSize;      / * 管理资源组BitMap的大小,用UINT32的个数表示 * /

  UINT32 uiRscBmpSize;       / * 资源池位图的大小,用UINT32的个数表示 */

  USHORT *pusMngRscCnt;  / * 每一行可分配资源个数 * /

  USHORT usBaseId;             / *  资源号基址加上资源索引即分配的资源号 */

  USHORT usPoolSize;          / * 资源池资源总数* /

  USHORT usPoolFreeSize;  / * 资源池可用资源总数 * /

  USHORT usCacheIndex;    / * 前一次分配的索引号 * /

  USHORT usMngCnt;          / * 管理资源池最大的行数,即是pucResourceCnt 的个数,表示行的个数 * /

  BOOL_T bReversed;         / * 资源池是否反转 * /

  spinlock stSpinLocK;          / * 资源池锁 * /

}DRV_L3_BMP_RSC_POOL_S;

 

 

ULONG DRV_L3_BmpPoolCreate

(

  IN USHORT usStartRscId,

  IN USHORT usEndRscId,

  OUT ULONG *puiHandle

)

{

  if (NULL == pulHandle)

  {

    return ERROR_FAILED;

  }

 

  if (usEndRscId > usStartRscId)

  {

    bReversed = BOOL_FALSE;

    uiPoolLen = usEndRscId - usStartRscId + 1;

  }

  else

  {

    bReversed = BOOL_TRUE;

    uiPoolLen = usStartRscId - usEndRscId + 1;

  }

  / *  计算需要管理资源池的列数

    每行管理256个资源,最后一个如果不足256,则需要补齐

    因此这部分管理bitmap的个数按照256个对齐计算

  * /

  uiMngCnt = DRV_L3_BMP_RSC_MNG_CNT(uiPoolLen);

  / * 计算管理资源池的列数用BITMAP方式表示,则计算需要bitmap的长度 * /

  uiBmpLen = DRV_L3_BITS_TO_UINT32(uiMngCnt);

}

 

posted @ 2018-07-17 16:52  陈饱饱你好呀  阅读(109)  评论(0编辑  收藏  举报