1
0
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:
Ludwig Ortmann 2013-07-05 19:22:29 +02:00 committed by Christian Mehlis
parent c989d2147e
commit 7dd9ac6be0
2 changed files with 25 additions and 0 deletions

View File

@ -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.
*

View File

@ -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];