嵌入式操作系统内核原理和开发(等值block内存池设计)
作者:网络转载 发布时间:[ 2012/10/18 10:28:39 ] 推荐标签:
上面是内存池的创建函数,入参共有五个参数,分别是mempool结构、名称、block大小、pool起始地址、pool大小。函数基本内容如下所示,
(1)判断内存池、指针参数合法性;
(2)检验指针是否n字节对齐,n取决于地址的大小;
(3)构建block链表,前后相连,后一个block指向NULL指针;
(4)将pool首地址赋值给raw_block_pool_available_list,函数返回。
RAW_U16 raw_block_allocate(MEM_POOL *pool_ptr, RAW_VOID **block_ptr, RAW_U32 wait_option)
{
RAW_U16 status;
RAW_U8 *work_ptr;
RAW_SR_ALLOC();
#if (RAW_BLOCK_FUNCTION_CHECK > 0)
if (pool_ptr == 0) {
return RAW_NULL_OBJECT;
}
if (block_ptr == 0) {
return RAW_NULL_POINTER;
}
if (raw_int_nesting) {
if (wait_option != RAW_NO_WAIT) {
return RAW_NOT_CALLED_BY_ISR;
}
}
#endif
RAW_CRITICAL_ENTER();
/* Determine if there is an available block. */
if (pool_ptr ->raw_block_pool_available) {
/* Yes, a block is available. Decrement the available count. */
pool_ptr ->raw_block_pool_available--;
/* Pickup the current block pointer. */
work_ptr = pool_ptr ->raw_block_pool_available_list;
/* Return the first available block to the caller. */
*((RAW_U8 **)block_ptr) = work_ptr;
/* Modify the available list to point at the next block in the pool. */
pool_ptr ->raw_block_pool_available_list = *((RAW_U8 **)work_ptr);
/* Set status to success. */
status = RAW_SUCCESS;
}
/*if no block memory is available then do it depend wait_option*/
else {
if (wait_option == RAW_NO_WAIT) {
*((RAW_U8 **)block_ptr) = 0;
RAW_CRITICAL_EXIT();
return RAW_NO_PEND_WAIT;
}
/*system is locked so task can not be blocked just return immediately*/
if (raw_sched_lock) {
*((RAW_U8 **)block_ptr) = 0;
RAW_CRITICAL_EXIT();
return RAW_SCHED_DISABLE;
}
raw_pend_object(&pool_ptr->common_block_obj, raw_task_active, wait_option);
RAW_CRITICAL_EXIT();
raw_sched();
RAW_CRITICAL_ENTER();
*((RAW_U8 **)block_ptr) = 0;
status = block_state_post_process(raw_task_active, block_ptr);
RAW_CRITICAL_EXIT();
}
return status;
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11