kernel: fix k_msgq_get/put() from ISR
There was no check to see if the current context was running an ISR when taking a decision whether to do a context switch or not. Change-Id: Ib9c426de8c0893b3d9383290bb59f6e0e41e9f52 Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
This commit is contained in:
parent
6a791a3286
commit
8215ce19ce
|
@ -1602,6 +1602,8 @@ extern void k_msgq_init(struct k_msgq *q, char *buffer,
|
|||
*
|
||||
* This routine sends a message to message queue @a q.
|
||||
*
|
||||
* @note Can be called by ISRs.
|
||||
*
|
||||
* @param q Address of the message queue.
|
||||
* @param data Pointer to the message.
|
||||
* @param timeout Waiting period to add the message (in milliseconds),
|
||||
|
@ -1619,6 +1621,8 @@ extern int k_msgq_put(struct k_msgq *q, void *data, int32_t timeout);
|
|||
* This routine receives a message from message queue @a q in a "first in,
|
||||
* first out" manner.
|
||||
*
|
||||
* @note Can be called by ISRs.
|
||||
*
|
||||
* @param q Address of the message queue.
|
||||
* @param data Address of area to hold the received message.
|
||||
* @param timeout Waiting period to receive the message (in milliseconds),
|
||||
|
|
|
@ -72,6 +72,8 @@ void k_msgq_init(struct k_msgq *q, char *buffer,
|
|||
|
||||
int k_msgq_put(struct k_msgq *q, void *data, int32_t timeout)
|
||||
{
|
||||
__ASSERT(!_is_in_isr() || timeout == K_NO_WAIT, "");
|
||||
|
||||
unsigned int key = irq_lock();
|
||||
struct k_thread *pending_thread;
|
||||
int result;
|
||||
|
@ -86,7 +88,7 @@ int k_msgq_put(struct k_msgq *q, void *data, int32_t timeout)
|
|||
_set_thread_return_value(pending_thread, 0);
|
||||
_abort_thread_timeout(pending_thread);
|
||||
_ready_thread(pending_thread);
|
||||
if (_must_switch_threads()) {
|
||||
if (!_is_in_isr() && _must_switch_threads()) {
|
||||
_Swap(key);
|
||||
return 0;
|
||||
}
|
||||
|
@ -117,6 +119,8 @@ int k_msgq_put(struct k_msgq *q, void *data, int32_t timeout)
|
|||
|
||||
int k_msgq_get(struct k_msgq *q, void *data, int32_t timeout)
|
||||
{
|
||||
__ASSERT(!_is_in_isr() || timeout == K_NO_WAIT, "");
|
||||
|
||||
unsigned int key = irq_lock();
|
||||
struct k_thread *pending_thread;
|
||||
int result;
|
||||
|
@ -146,7 +150,7 @@ int k_msgq_get(struct k_msgq *q, void *data, int32_t timeout)
|
|||
_set_thread_return_value(pending_thread, 0);
|
||||
_abort_thread_timeout(pending_thread);
|
||||
_ready_thread(pending_thread);
|
||||
if (_must_switch_threads()) {
|
||||
if (!_is_in_isr() && _must_switch_threads()) {
|
||||
_Swap(key);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue