From 6f6e1a6401eda000dce198150937c7919b4c9855 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 23 Feb 2011 18:59:39 +0000 Subject: Improved messages subsystem. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2759 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/chmsg.h | 41 ++++++++++++++++++++++++++++++++++------- os/kernel/include/chthreads.h | 22 ++++++++++++---------- 2 files changed, 46 insertions(+), 17 deletions(-) (limited to 'os/kernel/include') diff --git a/os/kernel/include/chmsg.h b/os/kernel/include/chmsg.h index 438da021f..b2e8ef51e 100644 --- a/os/kernel/include/chmsg.h +++ b/os/kernel/include/chmsg.h @@ -39,20 +39,47 @@ ((tp)->p_msgqueue.p_next != (Thread *)&(tp)->p_msgqueue) /** - * @brief Returns the first message in the queue. + * @brief Returns the message carried by the specified thread. + * @pre This function must be invoked immediately after exiting a call + * to @p chMsgWait(). * - * @iclass + * @param[in] tp pointer to the thread + * @return The message carried by the sender. + * + * @api + */ +#define chMsgGet(tp) ((tp)->p_msg) + +/** + * @brief Returns the message carried by the specified thread. + * @pre This function must be invoked immediately after exiting a call + * to @p chMsgWait(). + * + * @param[in] tp pointer to the thread + * @return The message carried by the sender. + * + * @sclass + */ +#define chMsgGetS(tp) ((tp)->p_msg) + +/** + * @brief Releases the thread waiting on top of the messages queue. + * @pre Invoke this function only after a message has been received + * using @p chMsgWait(). + * + * @param[in] tp pointer to the thread + * @param[in] msg message to be returned to the sender + * + * @sclass */ -#define chMsgGetI(tp) \ - ((tp)->p_msgqueue.p_next->p_msg) +#define chMsgReleaseS(tp, msg) chSchWakeupS(tp, msg) #ifdef __cplusplus extern "C" { #endif msg_t chMsgSend(Thread *tp, msg_t msg); - msg_t chMsgWait(void); - msg_t chMsgGet(void); - void chMsgRelease(msg_t msg); + Thread * chMsgWait(void); + void chMsgRelease(Thread *tp, msg_t msg); #ifdef __cplusplus } #endif diff --git a/os/kernel/include/chthreads.h b/os/kernel/include/chthreads.h index c22255ad0..f6ed23d1d 100644 --- a/os/kernel/include/chthreads.h +++ b/os/kernel/include/chthreads.h @@ -176,12 +176,14 @@ struct Thread { #define THD_STATE_WTOREVT 8 /** @brief Thread state: Waiting in @p chEvtWaitAllTimeout().*/ #define THD_STATE_WTANDEVT 9 -/** @brief Thread state: Waiting in @p chMsgSend().*/ -#define THD_STATE_SNDMSG 10 +/** @brief Thread state: Waiting in @p chMsgSend() (queued).*/ +#define THD_STATE_SNDMSGQ 10 +/** @brief Thread state: Waiting in @p chMsgSend() (not queued).*/ +#define THD_STATE_SNDMSG 11 /** @brief Thread state: Waiting in @p chMsgWait().*/ -#define THD_STATE_WTMSG 11 +#define THD_STATE_WTMSG 12 /** @brief Thread state: After termination.*/ -#define THD_STATE_FINAL 12 +#define THD_STATE_FINAL 13 /* * Various flags into the thread p_flags field. @@ -242,7 +244,7 @@ extern "C" { * @note This function is only available when the * @p CH_DBG_THREADS_PROFILING configuration option is enabled. * - * @param[in] tp the pointer to the thread + * @param[in] tp pointer to the thread * * @api */ @@ -258,7 +260,7 @@ extern "C" { /** * @brief Verifies if the specified thread is in the @p THD_STATE_FINAL state. * - * @param[in] tp the pointer to the thread + * @param[in] tp pointer to the thread * @retval TRUE thread terminated. * @retval FALSE thread not terminated. * @@ -279,7 +281,7 @@ extern "C" { /** * @brief Resumes a thread created with @p chThdInit(). * - * @param[in] tp the pointer to the thread + * @param[in] tp pointer to the thread * * @iclass */ @@ -305,7 +307,7 @@ extern "C" { * system clock. * @note The maximum specified value is implementation dependent. * - * @param[in] sec the time in seconds + * @param[in] sec time in seconds * * @api */ @@ -318,7 +320,7 @@ extern "C" { * system clock. * @note The maximum specified value is implementation dependent. * - * @param[in] msec the time in milliseconds + * @param[in] msec time in milliseconds * * @api */ @@ -331,7 +333,7 @@ extern "C" { * system clock. * @note The maximum specified value is implementation dependent. * - * @param[in] usec the time in microseconds + * @param[in] usec time in microseconds * * @api */ -- cgit v1.2.3