kernel: message does not execute correct put front behavior

When the buffer is full, Thread A gets pended (blocked).
If Thread B later calls the get function, it will unpend Thread A,
allowing it to resume and put the message into the queue.
In this situation, we need to know whether Thread A should
continue with put to front or put to end.

In order to resolve this issue, we don't allow set timeout
parameter for `k_msgq_put_front` and this parameter is always
`K_NO_WAIT`.

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>
This commit is contained in:
TaiJu Wu
2025-07-30 13:43:18 +08:00
committed by Anas Nashif
parent 2284bc2f3b
commit d361ec9692
3 changed files with 8 additions and 10 deletions

View File

@@ -5000,18 +5000,17 @@ __syscall int k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t time
* pointer is not retained, so the message content will not be modified
* by this function.
*
* @note k_msgq_put_front() does not block.
*
* @funcprops \isr_ok
*
* @param msgq Address of the message queue.
* @param data Pointer to the message.
* @param timeout Waiting period to add the message, or one of the special
* values K_NO_WAIT and K_FOREVER.
*
* @retval 0 Message sent.
* @retval -ENOMSG Returned without waiting or queue purged.
* @retval -EAGAIN Waiting period timed out.
*/
__syscall int k_msgq_put_front(struct k_msgq *msgq, const void *data, k_timeout_t timeout);
__syscall int k_msgq_put_front(struct k_msgq *msgq, const void *data);
/**
* @brief Receive a message from a message queue.

View File

@@ -228,9 +228,9 @@ int z_impl_k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t timeout
return put_msg_in_queue(msgq, data, timeout, true);
}
int z_impl_k_msgq_put_front(struct k_msgq *msgq, const void *data, k_timeout_t timeout)
int z_impl_k_msgq_put_front(struct k_msgq *msgq, const void *data)
{
return put_msg_in_queue(msgq, data, timeout, false);
return put_msg_in_queue(msgq, data, K_NO_WAIT, false);
}
#ifdef CONFIG_USERSPACE
@@ -244,13 +244,12 @@ static inline int z_vrfy_k_msgq_put(struct k_msgq *msgq, const void *data,
}
#include <zephyr/syscalls/k_msgq_put_mrsh.c>
static inline int z_vrfy_k_msgq_put_front(struct k_msgq *msgq, const void *data,
k_timeout_t timeout)
static inline int z_vrfy_k_msgq_put_front(struct k_msgq *msgq, const void *data)
{
K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ));
K_OOPS(K_SYSCALL_MEMORY_READ(data, msgq->msg_size));
return z_impl_k_msgq_put_front(msgq, data, timeout);
return z_impl_k_msgq_put_front(msgq, data);
}
#include <zephyr/syscalls/k_msgq_put_front_mrsh.c>
#endif /* CONFIG_USERSPACE */

View File

@@ -32,7 +32,7 @@ void producer_function(void *rec, void *p2, void *p3)
normal_data++;
}
printk("[producer] sending: %c (urgent)\n", urgent_data);
k_msgq_put_front(&my_msgq, &urgent_data, K_NO_WAIT);
k_msgq_put_front(&my_msgq, &urgent_data);
k_sleep(K_MSEC(100));
urgent_data++;