diff --git a/core/include/msg.h b/core/include/msg.h index 203b303ded..d18499ddbe 100644 --- a/core/include/msg.h +++ b/core/include/msg.h @@ -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); /** diff --git a/core/msg.c b/core/msg.c index ec16e94cab..1d89344e3d 100644 --- a/core/msg.c +++ b/core/msg.c @@ -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);