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

core/msg: handle error in msg_queue_capacity()

Rather than using an `assert()` on `thread_get()`, check for the thread
to exist and return a capacity of `0` if it does not.

This fixes compilation with `-fanalyzer` with `NDEBUG` defined, is more
consistent with other core APIs, and makes the API usable for threads
with a dynamic life cycle.

Co-authored-by: crasbe <crasbe@gmail.com>
This commit is contained in:
Marian Buschsieweke 2025-04-15 17:55:52 +02:00
parent 55f9d1c930
commit d36465d532
No known key found for this signature in database
GPG Key ID: 758BD52517F79C41
2 changed files with 7 additions and 4 deletions

View File

@ -393,10 +393,11 @@ unsigned msg_avail_thread(kernel_pid_t pid);
unsigned msg_avail(void);
/**
* @brief Get maximum capacity of a thread's queue length
* @brief Get maximum capacity of a thread's queue length
*
* @return Number of total messages that fit in the queue of @p pid on success
* @return 0, if no caller's message queue is initialized
* @return Number of total messages that fit in the queue of @p pid on success
* @retval 0 Either the thread identified by PID @p pid does not exist or
* has no message queue initialized (yet)
*/
unsigned msg_queue_capacity(kernel_pid_t pid);

View File

@ -484,7 +484,9 @@ unsigned msg_queue_capacity(kernel_pid_t pid)
thread_t *thread = thread_get(pid);
assert(thread != NULL);
if (!thread) {
return 0;
}
int queue_cap = 0;