optimize code

This commit is contained in:
Henson 2022-01-26 21:39:06 +08:00
parent 9b44535740
commit 500d26c257
5 changed files with 26 additions and 59 deletions

View File

@ -58,10 +58,7 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
RT_ASSERT(completion != RT_NULL);
/* current context checking */
if (timeout != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
result = RT_EOK;
thread = rt_thread_self();
@ -88,9 +85,6 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
rt_list_insert_before(&(completion->suspended_list),
&(thread->tlist));
/* current context checking */
RT_DEBUG_NOT_IN_INTERRUPT;
/* start timer */
if (timeout > 0)
{

View File

@ -99,10 +99,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
/* current context checking */
if (timeout != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
result = RT_EOK;
thread = rt_thread_self();
@ -221,10 +218,7 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
RT_ASSERT(size != RT_NULL);
/* current context checking */
if (timeout != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
result = RT_EOK;
thread = rt_thread_self();

View File

@ -129,7 +129,7 @@ int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
rt_base_t level;
/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE;
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
tick = rt_tick_from_millisecond(msec);

View File

@ -116,8 +116,10 @@ while (0)
* 2) not in interrupt context.
* 3) scheduler is not locked.
*/
#define RT_DEBUG_SCHEDULER_AVAILABLE \
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \
do \
{ \
if (need_check) \
{ \
rt_base_t level; \
level = rt_hw_interrupt_disable(); \
@ -130,11 +132,12 @@ do \
RT_DEBUG_IN_THREAD_CONTEXT; \
rt_hw_interrupt_enable(level); \
} \
} \
while (0)
#else
#define RT_DEBUG_NOT_IN_INTERRUPT
#define RT_DEBUG_IN_THREAD_CONTEXT
#define RT_DEBUG_SCHEDULER_AVAILABLE
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check)
#endif
#else /* RT_DEBUG */
@ -143,7 +146,7 @@ while (0)
#define RT_DEBUG_LOG(type, message)
#define RT_DEBUG_NOT_IN_INTERRUPT
#define RT_DEBUG_IN_THREAD_CONTEXT
#define RT_DEBUG_SCHEDULER_AVAILABLE
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check)
#endif /* RT_DEBUG */

View File

@ -484,11 +484,9 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
/* parameter check */
RT_ASSERT(sem != RT_NULL);
RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore);
/* current context checking */
if (time != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(time != 0);
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(sem->parent.parent)));
@ -914,13 +912,8 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
struct rt_thread *thread;
/* this function must not be used in interrupt even if time = 0 */
RT_DEBUG_IN_THREAD_CONTEXT;
/* current context checking */
if (time != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
/* parameter check */
RT_ASSERT(mutex != RT_NULL);
@ -1579,12 +1572,7 @@ rt_err_t rt_event_recv(rt_event_t event,
RT_ASSERT(rt_object_get_type(&event->parent.parent) == RT_Object_Class_Event);
/* current context checking */
RT_DEBUG_IN_THREAD_CONTEXT;
if (timeout != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
if (set == 0)
return -RT_ERROR;
@ -2008,10 +1996,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox);
/* current context checking */
if (timeout != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
/* initialize delta tick */
tick_delta = 0;
@ -2256,10 +2241,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout)
RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox);
/* current context checking */
if (timeout != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
/* initialize delta tick */
tick_delta = 0;
@ -2769,10 +2751,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq,
RT_ASSERT(size != 0);
/* current context checking */
if (timeout != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
/* greater than one message size */
if (size > mq->msg_size)
@ -3084,10 +3063,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq,
RT_ASSERT(size != 0);
/* current context checking */
if (timeout != 0)
{
RT_DEBUG_SCHEDULER_AVAILABLE;
}
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
/* initialize delta tick */
tick_delta = 0;