mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-24 05:53:49 +01:00
Merge pull request #21400 from maribu/core/msg-avail
core/msg: fix `msg_avail_thread()` and `msg_avail()`
This commit is contained in:
commit
a605d05eca
@ -375,16 +375,21 @@ int msg_reply_int(msg_t *m, msg_t *reply);
|
||||
*
|
||||
* @param[in] pid a PID
|
||||
*
|
||||
* @return Number of messages available in queue of @p pid on success
|
||||
* @return 0, if no caller's message queue is initialized
|
||||
* @return Number of messages available in queue of the thread identified by
|
||||
* PID @p pid
|
||||
* @retval 0 The message queue of the thread identified by PID @p pid is
|
||||
* *not* initialized or PID @p pid does not refer to a running
|
||||
* thread
|
||||
*/
|
||||
unsigned msg_avail_thread(kernel_pid_t pid);
|
||||
|
||||
/**
|
||||
* @brief Check how many messages are available (waiting) in the message queue
|
||||
*
|
||||
* @return Number of messages available in our queue on success
|
||||
* @return 0, if no caller's message queue is initialized
|
||||
* @pre The caller is running in thread context
|
||||
*
|
||||
* @return Number of messages available in our queue
|
||||
* @retval 0 Caller's message queue is *not* initialized
|
||||
*/
|
||||
unsigned msg_avail(void);
|
||||
|
||||
|
||||
15
core/msg.c
15
core/msg.c
@ -458,12 +458,23 @@ static unsigned _msg_avail(thread_t *thread)
|
||||
|
||||
unsigned msg_avail_thread(kernel_pid_t pid)
|
||||
{
|
||||
return _msg_avail(thread_get(pid));
|
||||
unsigned irq_state = irq_disable();
|
||||
thread_t *t = thread_get(pid);
|
||||
if (!t) {
|
||||
irq_restore(irq_state);
|
||||
return 0;
|
||||
}
|
||||
unsigned result = _msg_avail(t);
|
||||
irq_restore(irq_state);
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned msg_avail(void)
|
||||
{
|
||||
return _msg_avail(thread_get_active());
|
||||
unsigned irq_state = irq_disable();
|
||||
unsigned result = _msg_avail(thread_get_active());
|
||||
irq_restore(irq_state);
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned msg_queue_capacity(kernel_pid_t pid)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user