mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 22:43:50 +01:00
commit
603036208b
@ -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.
|
||||
*
|
||||
|
||||
18
core/msg.c
18
core/msg.c
@ -28,6 +28,9 @@
|
||||
//#define ENABLE_DEBUG
|
||||
#include "debug.h"
|
||||
|
||||
static int _msg_receive(msg_t *m, int block);
|
||||
|
||||
|
||||
static int queue_msg(tcb_t *target, msg_t *m)
|
||||
{
|
||||
int n = cib_put(&(target->msg_queue));
|
||||
@ -184,7 +187,17 @@ int msg_reply_int(msg_t *m, msg_t *reply)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int msg_try_receive(msg_t *m)
|
||||
{
|
||||
return _msg_receive(m, 0);
|
||||
}
|
||||
|
||||
int msg_receive(msg_t *m)
|
||||
{
|
||||
return _msg_receive(m, 1);
|
||||
}
|
||||
|
||||
static int _msg_receive(msg_t *m, int block)
|
||||
{
|
||||
dINT();
|
||||
DEBUG("%s: msg_receive.\n", active_thread->name);
|
||||
@ -197,6 +210,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…
x
Reference in New Issue
Block a user