1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

core: msg: introduce msg_try_send

This commit is contained in:
Kaspar Schleiser 2014-09-02 18:32:37 +02:00
parent 51d40ce524
commit bdcac07faa
2 changed files with 33 additions and 7 deletions

View File

@ -60,7 +60,7 @@ typedef struct msg {
/**
* @brief Send a message.
* @brief Send a message. (blocking)
*
* This function sends a message to another thread. The ``msg_t`` structure has
* to be allocated (e.g. on the stack) before calling the function and can be
@ -70,16 +70,33 @@ typedef struct msg {
* @param[in] m Pointer to preallocated ``msg_t`` structure, must
* not be NULL.
* @param[in] target_pid PID of target thread
* @param[in] block If not 0 and receiver is not receive-blocked,
* function will block. If not, function returns.
*
* @return 1, if sending was successful (message delivered directly or to a
* queue)
* @return 0, if called from ISR and receiver cannot receive the message now
* (it is not waiting or it's message queue is full)
* @return -1, on error (invalid PID)
*/
int msg_send(msg_t *m, kernel_pid_t target_pid);
/**
* @brief Send a message. (non-blocking)
*
* This function sends a message to another thread. The ``msg_t`` structure has
* to be allocated (e.g. on the stack) before calling the function and can be
* freed afterwards. This function will never block.
*
* @param[in] m Pointer to preallocated ``msg_t`` structure, must
* not be NULL.
* @param[in] target_pid PID of target thread
*
* @return 1, if sending was successful (message delivered directly or to a
* queue)
* @return 0, if receiver is not waiting or has a full message queue and
* ``block == 0``
* @return 0, if receiver is not waiting or has a full message queue
* @return -1, on error (invalid PID)
*/
int msg_send(msg_t *m, kernel_pid_t target_pid, bool block);
int msg_try_send(msg_t *m, kernel_pid_t target_pid);
/**

View File

@ -37,6 +37,7 @@
#include "thread.h"
static int _msg_receive(msg_t *m, int block);
static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block);
static int queue_msg(tcb_t *target, msg_t *m)
@ -51,7 +52,15 @@ static int queue_msg(tcb_t *target, msg_t *m)
return 0;
}
int msg_send(msg_t *m, kernel_pid_t target_pid, bool block)
int msg_send(msg_t *m, kernel_pid_t target_pid) {
return _msg_send(m, target_pid, true);
}
int msg_try_send(msg_t *m, kernel_pid_t target_pid) {
return _msg_send(m, target_pid, false);
}
static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block)
{
if (inISR()) {
return msg_send_int(m, target_pid);