程序清单 L7.5 OSMemPut() |
INT8U OSMemPut (OS_MEM *pmem, void *pblk) (1) |
{ |
OS_ENTER_CRITICAL(); |
if (pmem->OSMemNFree >= pmem->OSMemNBlks) { (2) |
OS_EXIT_CRITICAL(); |
return (OS_MEM_FULL); |
} |
*(void **)pblk = pmem->OSMemFreeList; (3) |
pmem->OSMemFreeList = pblk; |
pmem->OSMemNFree++; (4) |
OS_EXIT_CRITICAL(); |
return (OS_NO_ERR); |
} |
程序清单 L7.6 OS_MEM_DATA数据结构 |
typedef struct { |
void *OSAddr; /* 指向内存分区首地址的指针 */ |
void *OSFreeList; /* 指向空闲内存块链表首地址的指针 */ |
INT32U OSBlkSize; /* 每个内存块所含的字节数 */ |
INT32U OSNBlks; /* 内存分区总的内存块数 */ |
INT32U OSNFree; /* 空闲内存块总数 */ |
INT32U OSNUsed; /* 正在使用的内存块总数 */ |
} OS_MEM_DATA; |
程序清单 L7.7 OSMemQuery() |
INT8U OSMemQuery (OS_MEM *pmem, OS_MEM_DATA *pdata) |
{ |
OS_ENTER_CRITICAL(); |
pdata->OSAddr = pmem->OSMemAddr; (1) |
pdata->OSFreeList = pmem->OSMemFreeList; |
pdata->OSBlkSize = pmem->OSMemBlkSize; |
pdata->OSNBlks = pmem->OSMemNBlks; |
pdata->OSNFree = pmem->OSMemNFree; |
OS_EXIT_CRITICAL(); |
pdata->OSNUsed = pdata->OSNBlks - pdata->OSNFree; (2) |
return (OS_NO_ERR); |
} |
|
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |