Skip to content

Commit d361ec9

Browse files
TaiJuWunashif
authored andcommitted
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 <[email protected]>
1 parent 2284bc2 commit d361ec9

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

include/zephyr/kernel.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,18 +5000,17 @@ __syscall int k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t time
50005000
* pointer is not retained, so the message content will not be modified
50015001
* by this function.
50025002
*
5003+
* @note k_msgq_put_front() does not block.
5004+
*
50035005
* @funcprops \isr_ok
50045006
*
50055007
* @param msgq Address of the message queue.
50065008
* @param data Pointer to the message.
5007-
* @param timeout Waiting period to add the message, or one of the special
5008-
* values K_NO_WAIT and K_FOREVER.
50095009
*
50105010
* @retval 0 Message sent.
50115011
* @retval -ENOMSG Returned without waiting or queue purged.
5012-
* @retval -EAGAIN Waiting period timed out.
50135012
*/
5014-
__syscall int k_msgq_put_front(struct k_msgq *msgq, const void *data, k_timeout_t timeout);
5013+
__syscall int k_msgq_put_front(struct k_msgq *msgq, const void *data);
50155014

50165015
/**
50175016
* @brief Receive a message from a message queue.

kernel/msg_q.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ int z_impl_k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t timeout
228228
return put_msg_in_queue(msgq, data, timeout, true);
229229
}
230230

231-
int z_impl_k_msgq_put_front(struct k_msgq *msgq, const void *data, k_timeout_t timeout)
231+
int z_impl_k_msgq_put_front(struct k_msgq *msgq, const void *data)
232232
{
233-
return put_msg_in_queue(msgq, data, timeout, false);
233+
return put_msg_in_queue(msgq, data, K_NO_WAIT, false);
234234
}
235235

236236
#ifdef CONFIG_USERSPACE
@@ -244,13 +244,12 @@ static inline int z_vrfy_k_msgq_put(struct k_msgq *msgq, const void *data,
244244
}
245245
#include <zephyr/syscalls/k_msgq_put_mrsh.c>
246246

247-
static inline int z_vrfy_k_msgq_put_front(struct k_msgq *msgq, const void *data,
248-
k_timeout_t timeout)
247+
static inline int z_vrfy_k_msgq_put_front(struct k_msgq *msgq, const void *data)
249248
{
250249
K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ));
251250
K_OOPS(K_SYSCALL_MEMORY_READ(data, msgq->msg_size));
252251

253-
return z_impl_k_msgq_put_front(msgq, data, timeout);
252+
return z_impl_k_msgq_put_front(msgq, data);
254253
}
255254
#include <zephyr/syscalls/k_msgq_put_front_mrsh.c>
256255
#endif /* CONFIG_USERSPACE */

samples/kernel/msg_queue/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void producer_function(void *rec, void *p2, void *p3)
3232
normal_data++;
3333
}
3434
printk("[producer] sending: %c (urgent)\n", urgent_data);
35-
k_msgq_put_front(&my_msgq, &urgent_data, K_NO_WAIT);
35+
k_msgq_put_front(&my_msgq, &urgent_data);
3636
k_sleep(K_MSEC(100));
3737
urgent_data++;
3838

0 commit comments

Comments
 (0)