Skip to content

Commit 9e1210b

Browse files
committed
[kernel]add api rt_hw_interrupt_is_disabled
1 parent 8335c5a commit 9e1210b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

include/rtdebug.h

+8
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,22 @@ do \
125125
{ \
126126
if (need_check) \
127127
{ \
128+
rt_bool_t interrupt_disabled; \
128129
rt_base_t level; \
130+
interrupt_disabled = rt_hw_interrupt_is_disabled(); \
129131
level = rt_hw_interrupt_disable(); \
130132
if (rt_critical_level() != 0) \
131133
{ \
132134
rt_kprintf("Function[%s]: scheduler is not available\n", \
133135
__FUNCTION__); \
134136
RT_ASSERT(0) \
135137
} \
138+
if (interrupt_disabled == RT_TRUE) \
139+
{ \
140+
rt_kprintf("Function[%s]: interrupt is disabled\n", \
141+
__FUNCTION__); \
142+
RT_ASSERT(0) \
143+
} \
136144
RT_DEBUG_IN_THREAD_CONTEXT; \
137145
rt_hw_interrupt_enable(level); \
138146
} \

include/rthw.h

+2
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ void rt_hw_local_irq_enable(rt_base_t level);
127127
#define rt_hw_interrupt_disable rt_cpus_lock
128128
#define rt_hw_interrupt_enable rt_cpus_unlock
129129

130+
rt_bool_t rt_hw_interrupt_is_disabled(void);
130131
#else
131132
rt_base_t rt_hw_interrupt_disable(void);
132133
void rt_hw_interrupt_enable(rt_base_t level);
134+
rt_bool_t rt_hw_interrupt_is_disabled(void);
133135
#endif /*RT_USING_SMP*/
134136

135137
/*

src/ipc.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ static rt_err_t _rt_sem_take(rt_sem_t sem, rt_int32_t timeout, int suspend_flag)
505505

506506
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(sem->parent.parent)));
507507

508+
/* current context checking */
509+
RT_DEBUG_SCHEDULER_AVAILABLE(sem->value == 0 && timeout != 0);
510+
508511
/* disable interrupt */
509512
level = rt_hw_interrupt_disable();
510513

@@ -532,9 +535,6 @@ static rt_err_t _rt_sem_take(rt_sem_t sem, rt_int32_t timeout, int suspend_flag)
532535
}
533536
else
534537
{
535-
/* current context checking */
536-
RT_DEBUG_SCHEDULER_AVAILABLE(RT_TRUE);
537-
538538
/* semaphore is unavailable, push to suspend list */
539539
/* get current thread */
540540
thread = rt_thread_self();

src/irq.c

+6
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,14 @@ rt_weak rt_uint8_t rt_interrupt_get_nest(void)
135135
}
136136
RTM_EXPORT(rt_interrupt_get_nest);
137137

138+
138139
RTM_EXPORT(rt_hw_interrupt_disable);
139140
RTM_EXPORT(rt_hw_interrupt_enable);
140141

142+
rt_weak rt_bool_t rt_hw_interrupt_is_disabled(void)
143+
{
144+
return RT_FALSE;
145+
}
146+
RTM_EXPORT(rt_hw_interrupt_is_disabled);
141147
/**@}*/
142148

0 commit comments

Comments
 (0)