在 Rime 的回调函数中使用 process_post 是否安全? - 康蒂基
Is it safe to use process_post within a callback function of Rime? - Contiki
我正在使用 Rime,更具体地说是使用 runicast 示例。一旦收到消息,我将其存储在链表中,然后我 post 一个事件到负责从链表中提取消息并处理它们的进程。我的代码是这样的:
static void recv_runicast(struct runicast_conn *c,
const linkaddr_t *from, uint8_t seqno)
{
/*code to insert the message into the linked list*/
...
/*Post an event to the process which extracts messages from the linked list */
process_post(&extract_msg_from_linked_list, PROCESS_EVENT_CONTINUE, NULL);
}
我的问题是:在回调函数 recv_runicast 中使用 process_post 安全吗?或者我应该使用 process_poll?
提前致谢
是的,很安全。网络堆栈操作在进程上下文中完成,Contiki 进程不是抢占式的。所以几乎所有与流程相关的操作都是 "safe".
process_post
和process_poll
的主要区别是前者会在进程事件缓冲区中放入一个新的事件,而后者只是设置一个标志。所以第二个选项稍微更有效率。此外,理论上事件缓冲区可能会变满并且事件开始丢失,但这非常不太可能成为问题。
我会使用这些函数中的 none 个,但直接在回调中进行处理以简化执行流程。
我正在使用 Rime,更具体地说是使用 runicast 示例。一旦收到消息,我将其存储在链表中,然后我 post 一个事件到负责从链表中提取消息并处理它们的进程。我的代码是这样的:
static void recv_runicast(struct runicast_conn *c,
const linkaddr_t *from, uint8_t seqno)
{
/*code to insert the message into the linked list*/
...
/*Post an event to the process which extracts messages from the linked list */
process_post(&extract_msg_from_linked_list, PROCESS_EVENT_CONTINUE, NULL);
}
我的问题是:在回调函数 recv_runicast 中使用 process_post 安全吗?或者我应该使用 process_poll?
提前致谢
是的,很安全。网络堆栈操作在进程上下文中完成,Contiki 进程不是抢占式的。所以几乎所有与流程相关的操作都是 "safe".
process_post
和process_poll
的主要区别是前者会在进程事件缓冲区中放入一个新的事件,而后者只是设置一个标志。所以第二个选项稍微更有效率。此外,理论上事件缓冲区可能会变满并且事件开始丢失,但这非常不太可能成为问题。
我会使用这些函数中的 none 个,但直接在回调中进行处理以简化执行流程。