Merge pull request #3972 from mysterywolf/pr1

[bug fixed] add mutex values' overflow-check code
This commit is contained in:
Bernard Xiong 2020-10-21 17:51:58 +08:00 committed by GitHub
commit b0b1e0c1a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -37,7 +37,7 @@
* 2020-07-29 Meco Man fix thread->event_set/event_info when received an
* event without pending
* 2020-10-11 Meco Man add semaphore values' overflow-check code
* in the function of rt_sem_release
* 2020-10-21 Meco Man add mutex values' overflow-check code
*/
#include <rtthread.h>
@ -696,11 +696,19 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
thread->error = RT_EOK;
if (mutex->owner == thread)
{
if(mutex->hold < 255u)
{
/* it's the same thread */
mutex->hold ++;
}
else
{
rt_hw_interrupt_enable(temp); /* enable interrupt */
return -RT_EFULL; /* value overflowed */
}
}
else
{
#ifdef RT_USING_SIGNALS
__again: