1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-27 23:41:18 +01:00

Merge pull request #15478 from kaspar030/add_mbox_size_avail

core/mbox: add mbox_size(), mbox_avail()
This commit is contained in:
Kaspar Schleiser 2020-11-20 11:24:07 +01:00 committed by GitHub
commit c32358602a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -159,6 +159,32 @@ static inline int mbox_try_get(mbox_t *mbox, msg_t *msg)
return _mbox_get(mbox, msg, NON_BLOCKING);
}
/**
* @brief Get mbox queue size (capacity)
*
* @param[in] mbox ptr to mailbox to operate on
*
* @return size of mbox queue (or 0 if there's no queue)
*/
static inline size_t mbox_size(mbox_t *mbox)
{
return mbox->cib.mask ? mbox->cib.mask + 1 : 0;
}
/**
* @brief Get messages available in mbox
*
* Returns the number of messages that can be retrieved without blocking.
*
* @param[in] mbox ptr to mailbox to operate on
*
* @return number of available messages
*/
static inline size_t mbox_avail(mbox_t *mbox)
{
return cib_avail(&mbox->cib);
}
#ifdef __cplusplus
}
#endif

View File

@ -107,7 +107,7 @@ ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt_out,
}
#endif
if (reg->mbox.cib.mask != (GNRC_SOCK_MBOX_SIZE - 1)) {
if (mbox_size(&reg->mbox) != GNRC_SOCK_MBOX_SIZE) {
return -EINVAL;
}
#ifdef MODULE_XTIMER
@ -162,7 +162,7 @@ ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt_out,
*pkt_out = pkt; /* set out parameter */
#if IS_ACTIVE(SOCK_HAS_ASYNC)
if (reg->async_cb.generic && cib_avail(&reg->mbox.cib)) {
if (reg->async_cb.generic && mbox_avail(&reg->mbox)) {
reg->async_cb.generic(reg, SOCK_ASYNC_MSG_RECV, reg->async_cb_arg);
}
#endif