Skip to content

Commit 500d26c

Browse files
committed
optimize code
1 parent 9b44535 commit 500d26c

File tree

5 files changed

+26
-59
lines changed

5 files changed

+26
-59
lines changed

components/drivers/ipc/completion.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
5858
RT_ASSERT(completion != RT_NULL);
5959

6060
/* current context checking */
61-
if (timeout != 0)
62-
{
63-
RT_DEBUG_SCHEDULER_AVAILABLE;
64-
}
61+
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
6562

6663
result = RT_EOK;
6764
thread = rt_thread_self();
@@ -88,9 +85,6 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
8885
rt_list_insert_before(&(completion->suspended_list),
8986
&(thread->tlist));
9087

91-
/* current context checking */
92-
RT_DEBUG_NOT_IN_INTERRUPT;
93-
9488
/* start timer */
9589
if (timeout > 0)
9690
{

components/drivers/ipc/dataqueue.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
9999
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
100100

101101
/* current context checking */
102-
if (timeout != 0)
103-
{
104-
RT_DEBUG_SCHEDULER_AVAILABLE;
105-
}
102+
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
106103

107104
result = RT_EOK;
108105
thread = rt_thread_self();
@@ -221,10 +218,7 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
221218
RT_ASSERT(size != RT_NULL);
222219

223220
/* current context checking */
224-
if (timeout != 0)
225-
{
226-
RT_DEBUG_SCHEDULER_AVAILABLE;
227-
}
221+
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
228222

229223
result = RT_EOK;
230224
thread = rt_thread_self();

components/drivers/ipc/waitqueue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
129129
rt_base_t level;
130130

131131
/* current context checking */
132-
RT_DEBUG_SCHEDULER_AVAILABLE;
132+
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
133133

134134
tick = rt_tick_from_millisecond(msec);
135135

include/rtdebug.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,28 @@ while (0)
116116
* 2) not in interrupt context.
117117
* 3) scheduler is not locked.
118118
*/
119-
#define RT_DEBUG_SCHEDULER_AVAILABLE \
119+
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \
120120
do \
121121
{ \
122-
rt_base_t level; \
123-
level = rt_hw_interrupt_disable(); \
124-
if (rt_critical_level() != 0) \
122+
if (need_check) \
125123
{ \
126-
rt_kprintf("Function[%s]: scheduler is not available\n", \
127-
__FUNCTION__); \
128-
RT_ASSERT(0) \
124+
rt_base_t level; \
125+
level = rt_hw_interrupt_disable(); \
126+
if (rt_critical_level() != 0) \
127+
{ \
128+
rt_kprintf("Function[%s]: scheduler is not available\n", \
129+
__FUNCTION__); \
130+
RT_ASSERT(0) \
131+
} \
132+
RT_DEBUG_IN_THREAD_CONTEXT; \
133+
rt_hw_interrupt_enable(level); \
129134
} \
130-
RT_DEBUG_IN_THREAD_CONTEXT; \
131-
rt_hw_interrupt_enable(level); \
132135
} \
133136
while (0)
134137
#else
135138
#define RT_DEBUG_NOT_IN_INTERRUPT
136139
#define RT_DEBUG_IN_THREAD_CONTEXT
137-
#define RT_DEBUG_SCHEDULER_AVAILABLE
140+
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check)
138141
#endif
139142

140143
#else /* RT_DEBUG */
@@ -143,7 +146,7 @@ while (0)
143146
#define RT_DEBUG_LOG(type, message)
144147
#define RT_DEBUG_NOT_IN_INTERRUPT
145148
#define RT_DEBUG_IN_THREAD_CONTEXT
146-
#define RT_DEBUG_SCHEDULER_AVAILABLE
149+
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check)
147150

148151
#endif /* RT_DEBUG */
149152

src/ipc.c

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,9 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
484484
/* parameter check */
485485
RT_ASSERT(sem != RT_NULL);
486486
RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore);
487+
487488
/* current context checking */
488-
if (time != 0)
489-
{
490-
RT_DEBUG_SCHEDULER_AVAILABLE;
491-
}
489+
RT_DEBUG_SCHEDULER_AVAILABLE(time != 0);
492490

493491
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(sem->parent.parent)));
494492

@@ -914,13 +912,8 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
914912
struct rt_thread *thread;
915913

916914
/* this function must not be used in interrupt even if time = 0 */
917-
RT_DEBUG_IN_THREAD_CONTEXT;
918-
919915
/* current context checking */
920-
if (time != 0)
921-
{
922-
RT_DEBUG_SCHEDULER_AVAILABLE;
923-
}
916+
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
924917

925918
/* parameter check */
926919
RT_ASSERT(mutex != RT_NULL);
@@ -1579,12 +1572,7 @@ rt_err_t rt_event_recv(rt_event_t event,
15791572
RT_ASSERT(rt_object_get_type(&event->parent.parent) == RT_Object_Class_Event);
15801573

15811574
/* current context checking */
1582-
RT_DEBUG_IN_THREAD_CONTEXT;
1583-
1584-
if (timeout != 0)
1585-
{
1586-
RT_DEBUG_SCHEDULER_AVAILABLE;
1587-
}
1575+
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
15881576

15891577
if (set == 0)
15901578
return -RT_ERROR;
@@ -2008,10 +1996,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
20081996
RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox);
20091997

20101998
/* current context checking */
2011-
if (timeout != 0)
2012-
{
2013-
RT_DEBUG_SCHEDULER_AVAILABLE;
2014-
}
1999+
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
20152000

20162001
/* initialize delta tick */
20172002
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)
22562241
RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox);
22572242

22582243
/* current context checking */
2259-
if (timeout != 0)
2260-
{
2261-
RT_DEBUG_SCHEDULER_AVAILABLE;
2262-
}
2244+
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
22632245

22642246
/* initialize delta tick */
22652247
tick_delta = 0;
@@ -2769,10 +2751,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq,
27692751
RT_ASSERT(size != 0);
27702752

27712753
/* current context checking */
2772-
if (timeout != 0)
2773-
{
2774-
RT_DEBUG_SCHEDULER_AVAILABLE;
2775-
}
2754+
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
27762755

27772756
/* greater than one message size */
27782757
if (size > mq->msg_size)
@@ -3084,10 +3063,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq,
30843063
RT_ASSERT(size != 0);
30853064

30863065
/* current context checking */
3087-
if (timeout != 0)
3088-
{
3089-
RT_DEBUG_SCHEDULER_AVAILABLE;
3090-
}
3066+
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
30913067

30923068
/* initialize delta tick */
30933069
tick_delta = 0;

0 commit comments

Comments
 (0)