[src] bug fix in ipc.c (#7972)

Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
Shell 2023-08-23 12:20:14 +08:00 committed by GitHub
parent c26bb392b6
commit b1b21ddd2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 6 deletions

View File

@ -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;
}
}
}