aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel/src/chmboxes.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-02-21 18:00:06 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-02-21 18:00:06 +0000
commit17f0815d52977bd1e3e9e662d2ffdccbaf77a6bd (patch)
treec8b3af451582e77e9364817fa26466f942ee10df /os/kernel/src/chmboxes.c
parentfcb39bcbab4beeb5d1ce9bcbd886e54ac1321d34 (diff)
downloadChibiOS-17f0815d52977bd1e3e9e662d2ffdccbaf77a6bd.tar.gz
ChibiOS-17f0815d52977bd1e3e9e662d2ffdccbaf77a6bd.tar.bz2
ChibiOS-17f0815d52977bd1e3e9e662d2ffdccbaf77a6bd.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2756 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/kernel/src/chmboxes.c')
-rw-r--r--os/kernel/src/chmboxes.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c
index b2cef2470..e0b6ca014 100644
--- a/os/kernel/src/chmboxes.c
+++ b/os/kernel/src/chmboxes.c
@@ -156,6 +156,34 @@ msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) {
}
/**
+ * @brief Posts a message into a mailbox.
+ * @details This variant is non-blocking, the function returns a timeout
+ * condition if the queue is full.
+ *
+ * @param[in] mbp the pointer to an initialized Mailbox object
+ * @param[in] msg the message to be posted on the mailbox
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be
+ * posted.
+ *
+ * @iclass
+ */
+msg_t chMBPostI(Mailbox *mbp, msg_t msg) {
+
+ chDbgCheck(mbp != NULL, "chMBPostI");
+
+ if (chSemGetCounterI(&mbp->mb_emptysem) <= 0)
+ return RDY_TIMEOUT;
+ chSemFastWaitI(&mbp->mb_emptysem);
+ *mbp->mb_wrptr++ = msg;
+ if (mbp->mb_wrptr >= mbp->mb_top)
+ mbp->mb_wrptr = mbp->mb_buffer;
+ chSemSignalI(&mbp->mb_fullsem);
+ return RDY_OK;
+}
+
+/**
* @brief Posts an high priority message into a mailbox.
* @details The invoking thread waits until a empty slot in the mailbox becomes
* available or the specified time runs out.
@@ -219,6 +247,34 @@ msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) {
}
/**
+ * @brief Posts an high priority message into a mailbox.
+ * @details This variant is non-blocking, the function returns a timeout
+ * condition if the queue is full.
+ *
+ * @param[in] mbp the pointer to an initialized Mailbox object
+ * @param[in] msg the message to be posted on the mailbox
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be
+ * posted.
+ *
+ * @iclass
+ */
+msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) {
+
+ chDbgCheck(mbp != NULL, "chMBPostAheadI");
+
+ if (chSemGetCounterI(&mbp->mb_emptysem) <= 0)
+ return RDY_TIMEOUT;
+ chSemFastWaitI(&mbp->mb_emptysem);
+ if (--mbp->mb_rdptr < mbp->mb_buffer)
+ mbp->mb_rdptr = mbp->mb_top - 1;
+ *mbp->mb_rdptr = msg;
+ chSemSignalI(&mbp->mb_fullsem);
+ return RDY_OK;
+}
+
+/**
* @brief Retrieves a message from a mailbox.
* @details The invoking thread waits until a message is posted in the mailbox
* or the specified time runs out.
@@ -280,6 +336,33 @@ msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) {
}
return rdymsg;
}
+
+/**
+ * @brief Retrieves a message from a mailbox.
+ * @details This variant is non-blocking, the function returns a timeout
+ * condition if the queue is full.
+ *
+ * @param[in] mbp the pointer to an initialized Mailbox object
+ * @param[out] msgp pointer to a message variable for the received message
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly fetched.
+ * @retval RDY_TIMEOUT if the mailbox is empty and a message cannot be
+ * fetched.
+ *
+ * @iclass
+ */
+msg_t chMBFetchI(Mailbox *mbp, msg_t *msgp) {
+
+ chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchI");
+
+ if (chSemGetCounterI(&mbp->mb_fullsem) <= 0)
+ return RDY_TIMEOUT;
+ *msgp = *mbp->mb_rdptr++;
+ if (mbp->mb_rdptr >= mbp->mb_top)
+ mbp->mb_rdptr = mbp->mb_buffer;
+ chSemSignalI(&mbp->mb_emptysem);
+ return RDY_OK;
+}
#endif /* CH_USE_MAILBOXES */
/** @} */