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/src/chmsg.c | 59 ++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 41 deletions(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index c3b4848b0..d4199bbb0 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -75,7 +75,7 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { msg_insert(ctp, &tp->p_msgqueue); if (tp->p_state == THD_STATE_WTMSG) chSchReadyI(tp); - chSchGoSleepS(THD_STATE_SNDMSG); + chSchGoSleepS(THD_STATE_SNDMSGQ); msg = ctp->p_u.rdymsg; chSysUnlock(); return msg; @@ -83,69 +83,46 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { /** * @brief Suspends the thread and waits for an incoming message. - * @post After receiving a message the function @p chMsgRelease() must be - * invoked in order to acknowledge the reception and send the answer. + * @post After receiving a message the function @p chMsgGet() must be + * called in order to retrieve the message and then @p chMsgRelease() + * must be invoked in order to acknowledge the reception and send + * the answer. * @note If the message is a pointer then you can assume that the data * pointed by the message is stable until you invoke @p chMsgRelease() * because the sending thread is suspended until then. * - * @return The message. + * @return A reference to the thread carrying the message. * * @api */ -msg_t chMsgWait(void) { - msg_t msg; +Thread *chMsgWait(void) { + Thread *tp; chSysLock(); if (!chMsgIsPendingI(currp)) chSchGoSleepS(THD_STATE_WTMSG); -#if defined(CH_ARCHITECTURE_STM8) - msg = chMsgGetI((volatile Thread *)currp); /* Temporary hack.*/ -#else - msg = chMsgGetI(currp); -#endif + tp = fifo_remove(&currp->p_msgqueue); + tp->p_state = THD_STATE_SNDMSG; chSysUnlock(); - return msg; -} - -/** - * @brief Returns the next message in the queue. - * @post After receiving a message the function @p chMsgRelease() must be - * invoked in order to acknowledge the reception and send the answer. - * @note If the message is a pointer then you can assume that the data - * pointed by the message is stable until you invoke @p chMsgRelease() - * because the sending thread is suspended until then. - * - * @return The message. - * @retval 0 if the queue is empty. - * - * @api - */ -msg_t chMsgGet(void) { - msg_t msg; - - chSysLock(); - msg = chMsgIsPendingI(currp) ? chMsgGetI(currp) : (msg_t)NULL; - chSysUnlock(); - return msg; + return tp; } /** * @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() or @p chMsgGet(). + * using @p chMsgWait(). * - * @param[in] msg the message returned to the message sender + * @param[in] tp pointer to the thread + * @param[in] msg message to be returned to the sender * * @api */ -void chMsgRelease(msg_t msg) { +void chMsgRelease(Thread *tp, msg_t msg) { chSysLock(); - chDbgAssert(chMsgIsPendingI(currp), - "chMsgRelease(), #1", - "no message pending"); - chSchWakeupS(fifo_remove(&currp->p_msgqueue), msg); + chDbgAssert(tp->p_state == THD_STATE_SNDMSG, + "chMsgRelease(), #1", "invalid state"); + chMsgReleaseS(tp, msg); chSysUnlock(); } -- cgit v1.2.3 From e7e79a6ccb4f3e320b2b8b7bad1b14d65218641d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Mar 2011 18:38:08 +0000 Subject: License updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2827 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index d4199bbb0..5002a892a 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3