[bug fixed] add mb mq value overflow-check code

This commit is contained in:
mysterywolf 2020-10-22 07:13:49 +08:00
parent b0b1e0c1a4
commit b43f7365a4
1 changed files with 63 additions and 15 deletions

View File

@ -36,8 +36,7 @@
* 2019-09-16 tyx add send wait support for message queue
* 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
* 2020-10-21 Meco Man add mutex values' overflow-check code
* 2020-10-11 Meco Man add value overflow-check code
*/
#include <rtthread.h>
@ -724,9 +723,17 @@ __again:
/* set mutex owner and original priority */
mutex->owner = thread;
mutex->original_priority = thread->current_priority;
if(mutex->hold < 255u)
{
mutex->hold ++;
}
else
{
rt_hw_interrupt_enable(temp); /* enable interrupt */
return -RT_EFULL; /* value overflowed */
}
}
else
{
/* no waiting, return with timeout */
if (time == 0)
@ -881,7 +888,15 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
/* set new owner and priority */
mutex->owner = thread;
mutex->original_priority = thread->current_priority;
if(mutex->hold < 255u)
{
mutex->hold ++;
}
else
{
rt_hw_interrupt_enable(temp); /* enable interrupt */
return -RT_EFULL; /* value overflowed */
}
/* resume thread */
rt_ipc_list_resume(&(mutex->parent.suspend_thread));
@ -889,9 +904,17 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
need_schedule = RT_TRUE;
}
else
{
if(mutex->value < 65535u)
{
/* increase value */
mutex->value ++;
}
else
{
rt_hw_interrupt_enable(temp); /* enable interrupt */
return -RT_EFULL; /* value overflowed */
}
/* clear owner */
mutex->owner = RT_NULL;
@ -1583,8 +1606,17 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
++ mb->in_offset;
if (mb->in_offset >= mb->size)
mb->in_offset = 0;
if(mb->entry < 65535u)
{
/* increase message entry */
mb->entry ++;
}
else
{
rt_hw_interrupt_enable(temp); /* enable interrupt */
return -RT_EFULL; /* value overflowed */
}
/* resume suspended thread */
if (!rt_list_isempty(&mb->parent.suspend_thread))
@ -2147,8 +2179,16 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq,
if (mq->msg_queue_head == RT_NULL)
mq->msg_queue_head = msg;
if(mq->entry < 65535u)
{
/* increase message entry */
mq->entry ++;
}
else
{
rt_hw_interrupt_enable(temp); /* enable interrupt */
return -RT_EFULL; /* value overflowed */
}
/* resume suspended thread */
if (!rt_list_isempty(&mq->parent.suspend_thread))
@ -2247,8 +2287,16 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size)
if (mq->msg_queue_tail == RT_NULL)
mq->msg_queue_tail = msg;
if(mq->entry < 65535u)
{
/* increase message entry */
mq->entry ++;
}
else
{
rt_hw_interrupt_enable(temp); /* enable interrupt */
return -RT_EFULL; /* value overflowed */
}
/* resume suspended thread */
if (!rt_list_isempty(&mq->parent.suspend_thread))