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:
commit
c32358602a
@ -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
|
||||
|
||||
@ -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(®->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(®->mbox.cib)) {
|
||||
if (reg->async_cb.generic && mbox_avail(®->mbox)) {
|
||||
reg->async_cb.generic(reg, SOCK_ASYNC_MSG_RECV, reg->async_cb_arg);
|
||||
}
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user