diff options
| author | [email protected] <[email protected]> | 2011-06-12 10:01:48 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2011-06-12 10:01:48 +0000 |
| commit | 864bd1180237c952beefda21266c3f76f288b99a (patch) | |
| tree | 0d437761b4efee23c50b0a6e88e6a664fd55b2cf /include | |
| parent | 8c3d1e5eaec88d77a2fe623e9d478b9542bad040 (diff) | |
Add reentrance check. Put kernel debug switch together.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1494 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'include')
| -rw-r--r-- | include/rtdebug.h | 66 | ||||
| -rw-r--r-- | include/rtdef.h | 6 | ||||
| -rw-r--r-- | include/rtthread.h | 19 |
3 files changed, 85 insertions, 6 deletions
diff --git a/include/rtdebug.h b/include/rtdebug.h new file mode 100644 index 0000000000..735f5dba6f --- /dev/null +++ b/include/rtdebug.h @@ -0,0 +1,66 @@ +#ifndef __RTDEBUG_H__ +#define __RTDEBUG_H__ + +#include <rtconfig.h> + +/* Using this macro to control all kernel debug features. */ +#ifdef RT_DEBUG + +/* Turn on some of these (set to non-zero) to debug kernel */ +#define RT_DEBUG_MEM 0 +#define RT_DEBUG_MODULE 0 +#define RT_DEBUG_SCHEDULER 0 +#define RT_DEBUG_SLAB 0 +#define RT_DEBUG_THREAD 0 +#define RT_DEBUG_TIMER 0 +#define RT_DEBUG_IRQ 0 +#define RT_DEBUG_IPC 0 + +/* Turn on this to enable reentrance check */ +#define RT_DEBUG_REENT_CHK 1 + +#define RT_DEBUG_LOG(type,message) do{ if(type) rt_kprintf message;}while(0) + +#define RT_ASSERT(EX) if (!(EX)) {volatile char dummy=0;\ + rt_kprintf("(%s) assert failed at %s:%d \n", \ + #EX, __FUNCTION__, __LINE__); while (dummy==0);} + +/* Reentrance check */ +/* counter */ +extern rt_uint8_t rt_debug_reent_cnt; + +#define RT_DEBUG_REENT_IN if(RT_DEBUG_REENT_CHK){\ + rt_base_t level;\ + level = rt_hw_interrupt_disable();\ + rt_debug_reent_cnt++;\ + rt_hw_interrupt_enable(level);} + +#define RT_DEBUG_REENT_OUT if(RT_DEBUG_REENT_CHK){\ + rt_base_t level;\ + level = rt_hw_interrupt_disable();\ + rt_debug_reent_cnt--;\ + rt_hw_interrupt_enable(level);} + +/* Mark those non-reentrant functions with this macro */ +#define RT_DEBUG_NOT_REENT if(RT_DEBUG_REENT_CHK){\ + rt_base_t level;\ + level = rt_hw_interrupt_disable();\ + if(rt_debug_reent_cnt != 0){\ + rt_kprintf("Non-reentrant function used in critical area!\n");\ + RT_ASSERT(0)}\ + rt_hw_interrupt_enable(level);} + + +#else /* RT_DEBUG */ + +#define RT_ASSERT(EX) +#define RT_DEGUB_LOG(type,message) +#define RT_DEBUG_REENT_IN +#define RT_DEBUG_REENT_OUT +#define RT_DEBUG_NOT_REENT + +#endif /* RT_DEBUG */ + + + +#endif /* __RTDEBUG_H__ */ diff --git a/include/rtdef.h b/include/rtdef.h index f5d1449d45..50a02c56a3 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -149,12 +149,6 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RT_EBUSY 7 /**< Busy */ /*@}*/ -#ifdef RT_DEBUG -#define RT_ASSERT(EX) if (!(EX)) {volatile char dummy=0; rt_kprintf("(%s) assert failed at %s:%d \n", \ - #EX, __FUNCTION__, __LINE__); while (dummy==0);} -#else -#define RT_ASSERT(EX) -#endif /** * @ingroup BasicDef diff --git a/include/rtthread.h b/include/rtthread.h index 7793663873..95ab191397 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -21,6 +21,7 @@ #define __RT_THREAD_H__ #include <rtdef.h> +#include <rtdebug.h> #ifdef __cplusplus extern "C" { @@ -48,6 +49,24 @@ void rt_object_detach_sethook(void (*hook)(struct rt_object* object)); void rt_object_trytake_sethook(void (*hook)(struct rt_object* object)); void rt_object_take_sethook(void (*hook)(struct rt_object* object)); void rt_object_put_sethook(void (*hook)(struct rt_object* object)); +#define RT_OBJECT_HOOK_CALL(hookfunc)\ + do{\ + register rt_base_t temp;\ + temp = rt_hw_interrupt_disable();\ + RT_DEBUG_REENT_IN\ + if (hookfunc != RT_NULL) hookfunc();\ + RT_DEBUG_REENT_OUT\ + rt_hw_interrupt_enable(temp);\ + }while(0) +#define RT_OBJECT_HOOK_CALL2(hookfunc,...)\ + do{\ + register rt_base_t temp;\ + temp = rt_hw_interrupt_disable();\ + RT_DEBUG_REENT_IN\ + if (hookfunc != RT_NULL) hookfunc(__VA_ARGS__);\ + RT_DEBUG_REENT_OUT\ + rt_hw_interrupt_enable(temp);\ + }while(0) #endif /*@}*/ |
