diff --git a/os/rt/include/chmboxes.h b/os/rt/include/chmboxes.h index 7194dae46..357ee89c9 100644 --- a/os/rt/include/chmboxes.h +++ b/os/rt/include/chmboxes.h @@ -110,6 +110,7 @@ extern "C" { #endif void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n); void chMBReset(mailbox_t *mbp); + void chMBResetI(mailbox_t *mbp); msg_t chMBPost(mailbox_t *mbp, msg_t msg, systime_t timeout); msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t timeout); msg_t chMBPostI(mailbox_t *mbp, msg_t msg); diff --git a/os/rt/src/chmboxes.c b/os/rt/src/chmboxes.c index 31a5e5970..b7ae4f7d1 100644 --- a/os/rt/src/chmboxes.c +++ b/os/rt/src/chmboxes.c @@ -105,14 +105,29 @@ void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { */ void chMBReset(mailbox_t *mbp) { + chSysLock(); + chMBResetI(mbp); + chSchRescheduleS(); + chSysUnlock(); +} + +/** + * @brief Resets a @p mailbox_t object. + * @details All the waiting threads are resumed with status @p MSG_RESET and + * the queued messages are lost. + * + * @param[in] mbp the pointer to an initialized @p mailbox_t object + * + * @api + */ +void chMBResetI(mailbox_t *mbp) { + + chDbgCheckClassI(); chDbgCheck(mbp != NULL); - chSysLock(); mbp->mb_wrptr = mbp->mb_rdptr = mbp->mb_buffer; chSemResetI(&mbp->mb_emptysem, mbp->mb_top - mbp->mb_buffer); chSemResetI(&mbp->mb_fullsem, 0); - chSchRescheduleS(); - chSysUnlock(); } /**