嵌入式技术论坛
直播中

fanB

8年用户 1440经验值
擅长:20615
私信 关注
[经验]

RT_USING_HEAP该怎样去理解呢

在阅读rtt代码是发现RT_USING_HEAP宏(
/* Using Dynamic Heap Management */)
scheduler.c --> void rt_system_scheduler_init(void)中有
#ifdef RT_USING_HEAP
/* init thread defunct */
rt_list_init(&rt_thread_defunct);
#endif
初始化一个defunct的lists,很好奇如果不enable RT_USING_HEAP会出现什么情况,
请教bernard得知,RTT中thread创建是分为static和dynamic两种方式。

static方式即idle的创建方式:
static rt_uint8_t rt_thread_stack[IDLE_THREAD_STACK_SIZE];
静态的创建stack,

dynamic方式call rt_thread_create:
stack_start = (void*)rt_malloc(stack_size);
if (stack_start == RT_NULL)
{
/* allocate stack failure */
rt_object_delete((rt_object_t)thread);
return RT_NULL;
}
rt_malloc call Mem.c里的heap management function,换句话说,RTT提供了heap的dynamic管理机制。同时在thread 退出时放置到defunct的list,然后再切出current thread状态,idle这个静态的thread常驻内存,定时会回收defunct list里的僵死thread,这样有效的防止了thread context破坏,由此得到dynamic thread的创建和回收。

所以,不使用RT_USING_HEAP的macro,rt_thread_create会没有,需要自己提供回收thread的机制。

更多回帖

发帖
×
20
完善资料,
赚取积分