From 98d59d153e14d59af5fcb7db0afc66c885365525 Mon Sep 17 00:00:00 2001 From: "mbbill@gmail.com" Date: Wed, 13 Jul 2011 06:58:25 +0000 Subject: [PATCH] bugfix: thread->error will be changed unexpectedly when sending a mail in interrupt context. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1626 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- src/ipc.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/ipc.c b/src/ipc.c index 99f2f7fe27..a9ba1f150c 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1452,13 +1452,22 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout) /* parameter check */ RT_ASSERT(mb != RT_NULL); - tick_delta = 0; - RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(mb->parent.parent))); /* disable interrupt */ temp = rt_hw_interrupt_disable(); + /* for non-blocking call */ + if (mb->entry == 0 && timeout == 0) + { + rt_hw_interrupt_enable(temp); + return -RT_ETIMEOUT; + } + + RT_DEBUG_NOT_IN_INTERRUPT; + + tick_delta = 0; + /* get current thread */ thread = rt_thread_self(); @@ -1478,8 +1487,6 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout) return -RT_ETIMEOUT; } - RT_DEBUG_NOT_IN_INTERRUPT; - /* suspend current thread */ rt_ipc_list_suspend(&(mb->parent.suspend_thread), thread, mb->parent.parent.flag); @@ -1952,13 +1959,23 @@ rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeou RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(mq->parent.parent))); + /* disable interrupt */ + temp = rt_hw_interrupt_disable(); + + /* for non-blocking call */ + if (mq->entry == 0 && timeout == 0) + { + rt_hw_interrupt_enable(temp); + return -RT_ETIMEOUT; + } + + RT_DEBUG_NOT_IN_INTERRUPT; + tick_delta = 0; + /* get current thread */ thread = rt_thread_self(); - /* disable interrupt */ - temp = rt_hw_interrupt_disable(); - /* message queue is empty */ while (mq->entry == 0) { @@ -1975,7 +1992,6 @@ rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeou return -RT_ETIMEOUT; } - RT_DEBUG_NOT_IN_INTERRUPT; /* suspend current thread */ rt_ipc_list_suspend(&(mq->parent.suspend_thread), -- GitLab