mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Add msg_try_receive
This commit is contained in:
parent
c989d2147e
commit
7dd9ac6be0
@ -90,6 +90,16 @@ int msg_send_int(msg_t *m, unsigned int target_pid);
|
||||
*/
|
||||
int msg_receive(msg_t *m);
|
||||
|
||||
/**
|
||||
* @brief Try to receive a message.
|
||||
*
|
||||
* This function does not block if no message can be received.
|
||||
* @param m pointer to preallocated msg
|
||||
*
|
||||
* @return 1 if a message was received, -1 otherwise.
|
||||
*/
|
||||
int msg_try_receive(msg_t *m);
|
||||
|
||||
/**
|
||||
* @brief Send a message, block until reply received.
|
||||
*
|
||||
|
15
core/msg.c
15
core/msg.c
@ -184,7 +184,17 @@ int msg_reply_int(msg_t *m, msg_t *reply)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int msg_try_receive(msg_t *m)
|
||||
{
|
||||
return _msg_receive(m, false);
|
||||
}
|
||||
|
||||
int msg_receive(msg_t *m)
|
||||
{
|
||||
return _msg_receive(m, true);
|
||||
}
|
||||
|
||||
int _msg_receive(msg_t *m, block)
|
||||
{
|
||||
dINT();
|
||||
DEBUG("%s: msg_receive.\n", active_thread->name);
|
||||
@ -197,6 +207,11 @@ int msg_receive(msg_t *m)
|
||||
n = cib_get(&(me->msg_queue));
|
||||
}
|
||||
|
||||
/* no message, fail */
|
||||
if ((!block) && (n == -1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n >= 0) {
|
||||
DEBUG("%s: msg_receive(): We've got a queued message.\n", active_thread->name);
|
||||
*m = me->msg_array[n];
|
||||
|
Loading…
Reference in New Issue
Block a user