mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-24 05:04:10 +08:00
kernel: add RT_DEBUG_IN_THREAD_CONTEXT
In thread context means: 1) the scheduler has been started; 2) not in interrupt context. It is more stronger than RT_DEBUG_NOT_IN_INTERRUPT. With this commit, you will catch the error on situations like taking mutex before scheduling instead of crashing on NULL pointer reference.
This commit is contained in:
@@ -103,8 +103,29 @@ do \
|
||||
rt_hw_interrupt_enable(level); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* "In thread context" means:
|
||||
* 1) the scheduler has been started
|
||||
* 2) not in interrupt context.
|
||||
*/
|
||||
#define RT_DEBUG_IN_THREAD_CONTEXT \
|
||||
do \
|
||||
{ \
|
||||
rt_base_t level; \
|
||||
level = rt_hw_interrupt_disable(); \
|
||||
if (rt_thread_self() == RT_NULL) \
|
||||
{ \
|
||||
rt_kprintf("Function[%s] shall not be used before scheduler start\n", \
|
||||
__FUNCTION__); \
|
||||
RT_ASSERT(0) \
|
||||
} \
|
||||
RT_DEBUG_NOT_IN_INTERRUPT; \
|
||||
rt_hw_interrupt_enable(level); \
|
||||
} \
|
||||
while (0)
|
||||
#else
|
||||
#define RT_DEBUG_NOT_IN_INTERRUPT
|
||||
#define RT_DEBUG_IN_THREAD_CONTEXT
|
||||
#endif
|
||||
|
||||
#else /* RT_DEBUG */
|
||||
|
||||
Reference in New Issue
Block a user