From 7aef9f3ade37cea5326c6052558aacbcb42b4a0e Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 9 Apr 2017 10:20:45 +0000 Subject: New mailboxes implementation. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10150 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/common/oslib/include/chmboxes.h | 53 +++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'os/common/oslib/include/chmboxes.h') diff --git a/os/common/oslib/include/chmboxes.h b/os/common/oslib/include/chmboxes.h index cc1d743df..8b4498e3d 100644 --- a/os/common/oslib/include/chmboxes.h +++ b/os/common/oslib/include/chmboxes.h @@ -60,10 +60,10 @@ typedef struct { after the buffer. */ msg_t *wrptr; /**< @brief Write pointer. */ msg_t *rdptr; /**< @brief Read pointer. */ - semaphore_t fullsem; /**< @brief Full counter - @p semaphore_t. */ - semaphore_t emptysem; /**< @brief Empty counter - @p semaphore_t. */ + cnt_t cnt; /**< @brief Messages in queue. */ + bool reset; /**< @brief True in reset state. */ + threads_queue_t qw; /**< @brief Queued writers. */ + threads_queue_t qr; /**< @brief Queued readers. */ } mailbox_t; /*===========================================================================*/ @@ -84,8 +84,10 @@ typedef struct { (msg_t *)(buffer) + size, \ (msg_t *)(buffer), \ (msg_t *)(buffer), \ - _SEMAPHORE_DATA(name.fullsem, 0), \ - _SEMAPHORE_DATA(name.emptysem, size), \ + (cnt_t)0, \ + false, \ + _THREADS_QUEUE_DATA(name.qw), \ + _THREADS_QUEUE_DATA(name.qr), \ } /** @@ -128,57 +130,54 @@ extern "C" { /*===========================================================================*/ /** - * @brief Returns the mailbox buffer size. + * @brief Returns the mailbox buffer size as number of messages. * * @param[in] mbp the pointer to an initialized mailbox_t object * @return The size of the mailbox. * * @iclass */ -static inline size_t chMBGetSizeI(mailbox_t *mbp) { +static inline cnt_t chMBGetSizeI(mailbox_t *mbp) { /*lint -save -e9033 [10.8] Perfectly safe pointers arithmetic.*/ - return (size_t)(mbp->top - mbp->buffer); + return (cnt_t)(mbp->top - mbp->buffer); /*lint -restore*/ } /** - * @brief Returns the number of free message slots into a mailbox. - * @note Can be invoked in any system state but if invoked out of a locked - * state then the returned value may change after reading. - * @note The returned value can be less than zero when there are waiting - * threads on the internal semaphore. + * @brief Returns the number of used message slots into a mailbox. * * @param[in] mbp the pointer to an initialized mailbox_t object - * @return The number of empty message slots. + * @return The number of queued messages. + * @retval QUEUE_RESET if the queue is in reset state. * * @iclass */ -static inline cnt_t chMBGetFreeCountI(mailbox_t *mbp) { +static inline cnt_t chMBGetUsedCountI(mailbox_t *mbp) { chDbgCheckClassI(); - return chSemGetCounterI(&mbp->emptysem); + return mbp->cnt; } /** - * @brief Returns the number of used message slots into a mailbox. + * @brief Returns the number of free message slots into a mailbox. * @note Can be invoked in any system state but if invoked out of a locked * state then the returned value may change after reading. * @note The returned value can be less than zero when there are waiting * threads on the internal semaphore. * * @param[in] mbp the pointer to an initialized mailbox_t object - * @return The number of queued messages. + * @return The number of empty message slots. * * @iclass */ -static inline cnt_t chMBGetUsedCountI(mailbox_t *mbp) { +static inline cnt_t chMBGetFreeCountI(mailbox_t *mbp) { chDbgCheckClassI(); - return chSemGetCounterI(&mbp->fullsem); + return chMBGetSizeI(mbp) - chMBGetUsedCountI(mbp); } /** @@ -200,6 +199,18 @@ static inline msg_t chMBPeekI(mailbox_t *mbp) { return *mbp->rdptr; } +/** + * @brief Terminates the reset state. + * + * @param[in] mbp the pointer to an initialized mailbox_t object + * + * @xclass + */ +static inline void chMBResumeX(mailbox_t *mbp) { + + mbp->reset = false; +} + #endif /* CH_CFG_USE_MAILBOXES == TRUE */ #endif /* CHMBOXES_H */ -- cgit v1.2.3