这几天再看rt-thread的使用例程,还没有深入到内核级别。编写采用类似Linux的封装形式,c语言面向对象风格。有个地方看得还是感觉不太懂,感觉有点怪。
{
char *str;
while (1)
{
rt_kprintf("thread1: try to recv a mail\n");
if (rt_mb_recv(&mb, (rt_uint32_t *)&str, RT_WAITING_FOREVER) == RT_EOK)
// if (rt_mb_recv(&mb, (rt_uint32_t *)str, RT_WAITING_FOREVER) == RT_EOK)
{
rt_kprintf("thread1: get a mail from mailbox, the content:%s\n", str);
if (str == mb_str3)
break;
rt_thread_mdelay(100);
}
}
rt_mb_detach(&mb);
}
char *str 是个野指针,通过取值操作在rt_mb_recv函数中初始化,比较难懂。试了下去掉取地址操作还不行。是不是有更好的表达方式呢?
在rt_err_t rt_mb_recv函数中的赋值操作如下
/**
* This function will receive a mail from mailbox object, if there is no mail
* in mailbox object, the thread shall wait for a specified time.
*
* @param mb the mailbox object
* @param value the received mail will be saved in
* @param timeout the waiting time
*
* @return the error code
*/
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout)
/* fill ptr */
*value = mb->msg_pool[mb->out_offset];