From 11b93655420e0eb5251e14fff948d44119aa50d8 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Sun, 16 Jun 2019 08:43:48 -0400 Subject: [PATCH] kernel: msgq: error handling Add runtime error handling for k_msgq_cleanup. We return 0 on success now and -EAGAIN when cleanup is not possible. Signed-off-by: Anas Nashif --- include/kernel.h | 4 +++- kernel/msg_q.c | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/kernel.h b/include/kernel.h index 4e451259bd8..ee86c719b02 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -3698,8 +3698,10 @@ __syscall int k_msgq_alloc_init(struct k_msgq *msgq, size_t msg_size, * * @param msgq message queue to cleanup * + * @retval 0 on success + * @retval -EBUSY Queue not empty */ -void k_msgq_cleanup(struct k_msgq *msgq); +int k_msgq_cleanup(struct k_msgq *msgq); /** * @brief Send a message to a message queue. diff --git a/kernel/msg_q.c b/kernel/msg_q.c index 84a21deb5ba..1d172f51104 100644 --- a/kernel/msg_q.c +++ b/kernel/msg_q.c @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef CONFIG_OBJECT_TRACING @@ -98,14 +99,17 @@ int z_vrfy_k_msgq_alloc_init(struct k_msgq *q, size_t msg_size, #include #endif -void k_msgq_cleanup(struct k_msgq *msgq) +int k_msgq_cleanup(struct k_msgq *msgq) { - __ASSERT_NO_MSG(z_waitq_head(&msgq->wait_q) == NULL); + CHECKIF(z_waitq_head(&msgq->wait_q) != NULL) { + return -EBUSY; + } if ((msgq->flags & K_MSGQ_FLAG_ALLOC) != 0) { k_free(msgq->buffer_start); msgq->flags &= ~K_MSGQ_FLAG_ALLOC; } + return 0; }