diff options
| author | Shell <[email protected]> | 2023-08-23 12:20:14 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-23 12:20:14 +0800 |
| commit | b1b21ddd2b185ab567e00253eea356c077c9e99e (patch) | |
| tree | c1a42fd3a1666d5f2e48cc903df450af70780a13 | |
| parent | c26bb392b6cd18ea9587be220a894abb70891461 (diff) | |
[src] bug fix in ipc.c (#7972)
Signed-off-by: Shell <[email protected]>
| -rw-r--r-- | src/ipc.c | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -956,8 +956,14 @@ void rt_mutex_drop_thread(rt_mutex_t mutex, rt_thread_t thread) rt_list_remove(&(thread->tlist)); - /* should change the priority of mutex owner thread */ - if (mutex->owner->current_priority == thread->current_priority) + /** + * Should change the priority of mutex owner thread + * Note: After current thread is detached from mutex pending list, there is + * a chance that the mutex owner has been released the mutex. Which + * means mutex->owner can be NULL at this point. If that happened, + * it had already reset its priority. So it's okay to skip + */ + if (mutex->owner && mutex->owner->current_priority == thread->current_priority) need_update = RT_TRUE; /* update the priority of mutex */ @@ -1304,8 +1310,14 @@ static rt_err_t _rt_mutex_take(rt_mutex_t mutex, rt_int32_t timeout, int suspend rt_bool_t need_update = RT_FALSE; - /* should change the priority of mutex owner thread */ - if (mutex->owner->current_priority == thread->current_priority) + /** + * Should change the priority of mutex owner thread + * Note: After current thread is detached from mutex pending list, there is + * a chance that the mutex owner has been released the mutex. Which + * means mutex->owner can be NULL at this point. If that happened, + * it had already reset its priority. So it's okay to skip + */ + if (mutex->owner && mutex->owner->current_priority == thread->current_priority) need_update = RT_TRUE; /* update the priority of mutex */ @@ -1340,8 +1352,12 @@ static rt_err_t _rt_mutex_take(rt_mutex_t mutex, rt_int32_t timeout, int suspend /* enable interrupt */ rt_hw_interrupt_enable(level); - /* return error */ - return thread->error; + /* clear pending object before exit */ + thread->pending_object = RT_NULL; + + /* fix thread error number to negative value and return */ + ret = thread->error; + return ret > 0 ? -ret : ret; } } } |
