change the RT_DEBUG_NOT_REENT to RT_DEBUG_NOT_IN_INTERRUPT.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1503 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2011-06-14 23:59:42 +00:00
parent 99dc4465a6
commit ee68988518
15 changed files with 139 additions and 242 deletions

View File

@ -39,9 +39,9 @@
#define RT_DEBUG_IPC 0
#endif
/* Turn on this to enable reentrance check */
#ifndef RT_DEBUG_REENT_CHK
#define RT_DEBUG_REENT_CHK 1
/* Turn on this to enable context check */
#ifndef RT_DEBUG_CONTEXT_CHECK
#define RT_DEBUG_CONTEXT_CHECK 1
#endif
#define RT_DEBUG_LOG(type,message) do{ if(type) rt_kprintf message;}while(0)
@ -50,39 +50,21 @@
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){\
/* Macro to check current context */
#if RT_DEBUG_CONTEXT_CHECK
#define RT_DEBUG_NOT_IN_INTERRUPT do {\
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");\
if(rt_interrupt_get_nest() != 0){\
rt_kprintf("Function[%s] shall not used in ISR\n", __FUNCTION__);\
RT_ASSERT(0)}\
rt_hw_interrupt_enable(level);}
rt_hw_interrupt_enable(level);} while (0)
#endif
#else /* RT_DEBUG */
#define RT_ASSERT(EX)
#define RT_DEBUG_LOG(type,message)
#define RT_DEBUG_REENT_IN
#define RT_DEBUG_REENT_OUT
#define RT_DEBUG_NOT_REENT
#define RT_DEBUG_NOT_IN_INTERRUPT
#endif /* RT_DEBUG */

View File

@ -264,6 +264,17 @@ struct rt_object_information
rt_list_t object_list; /**< object list */
rt_size_t object_size; /**< object size */
};
/**
* The hook function call macro
*/
#ifdef RT_USING_HOOK
#define RT_OBJECT_HOOK_CALL(func, argv) \
do { if ((func) != RT_NULL) func argv; } while (0)
#else
#define RT_OBJECT_HOOK_CALL(func, argv)
#endif
/*@}*/
/**

View File

@ -36,6 +36,7 @@ extern "C" {
*/
void rt_system_object_init(void);
struct rt_object_information *rt_object_get_information(enum rt_object_class_type type);
void rt_object_init(struct rt_object* object, enum rt_object_class_type type, const char* name);
void rt_object_detach(rt_object_t object);
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name);
@ -49,24 +50,6 @@ 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
/*@}*/
@ -346,6 +329,10 @@ typedef void (*rt_isr_handler_t)(int vector);
*/
void rt_interrupt_enter(void);
void rt_interrupt_leave(void);
/*
* the number of nested interrupts.
*/
rt_uint8_t rt_interrupt_get_nest(void);
/**
* @addtogroup KernelService

View File

@ -1,28 +0,0 @@
/*
* File : debug.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2011-06 11 mbbill first version
*/
#include <rtdef.h>
#include <rtdebug.h>
/**
* @addtogroup Kernel
*/
/*@{*/
#ifdef RT_DEBUG
rt_uint8_t rt_debug_reent_cnt = 0;
#endif
/*@}*/

View File

@ -60,8 +60,7 @@ void rt_thread_idle_sethook(void (*hook)())
*/
void rt_thread_idle_excute(void)
{
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* check the defunct thread list */
if (!rt_list_isempty(&rt_thread_defunct))
@ -149,9 +148,10 @@ static void rt_thread_idle_entry(void* parameter)
{
while (1)
{
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL(rt_thread_idle_hook);
#endif
#ifdef RT_USING_HOOK
if (rt_thread_idle_hook != RT_NULL)
rt_thread_idle_hook();
#endif
rt_thread_idle_excute();
}

106
src/ipc.c
View File

@ -41,8 +41,6 @@
#include "kservice.h"
/* #define RT_IPC_DEBUG */
#ifdef RT_USING_HOOK
extern void (*rt_object_trytake_hook)(struct rt_object* object);
extern void (*rt_object_take_hook)(struct rt_object* object);
@ -251,7 +249,7 @@ rt_sem_t rt_sem_create (const char* name, rt_uint32_t value, rt_uint8_t flag)
{
rt_sem_t sem;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
sem = (rt_sem_t) rt_object_allocate(RT_Object_Class_Semaphore, name);
@ -280,7 +278,7 @@ rt_sem_t rt_sem_create (const char* name, rt_uint32_t value, rt_uint8_t flag)
*/
rt_err_t rt_sem_delete (rt_sem_t sem)
{
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
RT_ASSERT(sem != RT_NULL);
@ -310,9 +308,7 @@ rt_err_t rt_sem_take (rt_sem_t sem, rt_int32_t time)
RT_ASSERT(sem != RT_NULL);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(sem->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(sem->parent.parent)));
/* disable interrupt */
temp = rt_hw_interrupt_disable();
@ -339,8 +335,8 @@ rt_err_t rt_sem_take (rt_sem_t sem, rt_int32_t time)
}
else
{
/* time = 0 is ok */
RT_DEBUG_NOT_REENT
/* current context checking */
RT_DEBUG_NOT_IN_INTERRUPT;
/* semaphore is unavailable, push to suspend list */
/* get current thread */
@ -379,9 +375,7 @@ rt_err_t rt_sem_take (rt_sem_t sem, rt_int32_t time)
}
}
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(sem->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(sem->parent.parent)));
return RT_EOK;
}
@ -411,9 +405,7 @@ rt_err_t rt_sem_release(rt_sem_t sem)
register rt_base_t temp;
register rt_bool_t need_schedule;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(sem->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(sem->parent.parent)));
need_schedule = RT_FALSE;
@ -552,7 +544,7 @@ rt_mutex_t rt_mutex_create (const char* name, rt_uint8_t flag)
{
struct rt_mutex *mutex;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
mutex = (rt_mutex_t) rt_object_allocate(RT_Object_Class_Mutex, name);
@ -583,7 +575,7 @@ rt_mutex_t rt_mutex_create (const char* name, rt_uint8_t flag)
*/
rt_err_t rt_mutex_delete (rt_mutex_t mutex)
{
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
RT_ASSERT(mutex != RT_NULL);
@ -612,7 +604,7 @@ 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_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
RT_ASSERT(mutex != RT_NULL);
@ -622,9 +614,7 @@ rt_err_t rt_mutex_take (rt_mutex_t mutex, rt_int32_t time)
/* get current thread */
thread = rt_thread_self();
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(mutex->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(mutex->parent.parent)));
RT_DEBUG_LOG(RT_DEBUG_IPC,
("mutex_take: current thread %s, mutex value: %d, hold: %d\n",
@ -719,9 +709,7 @@ rt_err_t rt_mutex_take (rt_mutex_t mutex, rt_int32_t time)
/* enable interrupt */
rt_hw_interrupt_enable(temp);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(mutex->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(mutex->parent.parent)));
return RT_EOK;
}
@ -752,9 +740,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
("mutex_release:current thread %s, mutex value: %d, hold: %d\n",
thread->name, mutex->value, mutex->hold));
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(mutex->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mutex->parent.parent)));
/* mutex only can be released by owner */
if (thread != mutex->owner)
@ -899,7 +885,7 @@ rt_event_t rt_event_create (const char* name, rt_uint8_t flag)
{
rt_event_t event;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
event = (rt_event_t) rt_object_allocate(RT_Object_Class_Event, name);
@ -929,7 +915,7 @@ rt_err_t rt_event_delete (rt_event_t event)
/* parameter check */
RT_ASSERT(event != RT_NULL);
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* resume all suspended thread */
rt_ipc_list_resume_all(&(event->parent.suspend_thread));
@ -963,9 +949,7 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set)
if (set == 0) return -RT_ERROR;
need_schedule = RT_FALSE;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(event->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(event->parent.parent)));
/* disable interrupt */
level = rt_hw_interrupt_disable();
@ -1051,7 +1035,7 @@ rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_
register rt_ubase_t level;
register rt_base_t status;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* parameter check */
RT_ASSERT(event != RT_NULL);
@ -1064,9 +1048,7 @@ rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_
/* reset thread error */
thread->error = RT_EOK;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(event->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(event->parent.parent)));
/* disable interrupt */
level = rt_hw_interrupt_disable();
@ -1134,9 +1116,7 @@ rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_
/* enable interrupt */
rt_hw_interrupt_enable(level);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(event->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(event->parent.parent)));
return thread->error;
}
@ -1254,7 +1234,7 @@ rt_mailbox_t rt_mb_create (const char* name, rt_size_t size, rt_uint8_t flag)
{
rt_mailbox_t mb;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
mb = (rt_mailbox_t) rt_object_allocate(RT_Object_Class_MailBox, name);
@ -1295,7 +1275,7 @@ rt_mailbox_t rt_mb_create (const char* name, rt_size_t size, rt_uint8_t flag)
*/
rt_err_t rt_mb_delete (rt_mailbox_t mb)
{
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* parameter check */
RT_ASSERT(mb != RT_NULL);
@ -1342,9 +1322,7 @@ rt_err_t rt_mb_send_wait (rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout
/* parameter check */
RT_ASSERT(mb != RT_NULL);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(mb->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mb->parent.parent)));
/* disable interrupt */
temp = rt_hw_interrupt_disable();
@ -1368,7 +1346,7 @@ rt_err_t rt_mb_send_wait (rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout
return -RT_EFULL;
}
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* suspend current thread */
rt_ipc_list_suspend(&(mb->suspend_sender_thread),
@ -1475,9 +1453,8 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
RT_ASSERT(mb != RT_NULL);
tick_delta = 0;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(mb->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(mb->parent.parent)));
/* disable interrupt */
temp = rt_hw_interrupt_disable();
@ -1501,7 +1478,7 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
return -RT_ETIMEOUT;
}
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* suspend current thread */
rt_ipc_list_suspend(&(mb->parent.suspend_thread),
@ -1563,9 +1540,8 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
/* enable interrupt */
rt_hw_interrupt_enable(temp);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(mb->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(mb->parent.parent)));
rt_schedule();
return RT_EOK;
@ -1574,9 +1550,7 @@ rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
/* enable interrupt */
rt_hw_interrupt_enable(temp);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(mb->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(mb->parent.parent)));
return RT_EOK;
}
@ -1724,7 +1698,7 @@ rt_mq_t rt_mq_create (const char* name, rt_size_t msg_size, rt_size_t max_msgs,
struct rt_mq_message* head;
register rt_base_t temp;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
mq = (rt_mq_t) rt_object_allocate(RT_Object_Class_MessageQueue, name);
@ -1779,7 +1753,7 @@ rt_mq_t rt_mq_create (const char* name, rt_size_t msg_size, rt_size_t max_msgs,
*/
rt_err_t rt_mq_delete (rt_mq_t mq)
{
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* parameter check */
RT_ASSERT(mq != RT_NULL);
@ -1822,9 +1796,7 @@ rt_err_t rt_mq_send (rt_mq_t mq, void* buffer, rt_size_t size)
/* greater than one message size */
if (size > mq->msg_size) return -RT_ERROR;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(mq->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mq->parent.parent)));
/* disable interrupt */
temp = rt_hw_interrupt_disable();
@ -1905,9 +1877,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, void* buffer, rt_size_t size)
/* greater than one message size */
if (size > mq->msg_size) return -RT_ERROR;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(mq->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mq->parent.parent)));
/* disable interrupt */
temp = rt_hw_interrupt_disable();
@ -1980,9 +1950,7 @@ rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeou
struct rt_mq_message *msg;
rt_uint32_t tick_delta;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_trytake_hook,&(mq->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(mq->parent.parent)));
tick_delta = 0;
/* get current thread */
@ -2007,7 +1975,7 @@ rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeou
return -RT_ETIMEOUT;
}
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* suspend current thread */
rt_ipc_list_suspend(&(mq->parent.suspend_thread),
@ -2078,9 +2046,7 @@ rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeou
/* enable interrupt */
rt_hw_interrupt_enable(temp);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(mq->parent.parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(mq->parent.parent)));
return RT_EOK;
}

View File

@ -37,8 +37,6 @@ void rt_interrupt_enter()
{
rt_base_t level;
RT_DEBUG_REENT_IN
RT_DEBUG_LOG(RT_DEBUG_IRQ,("irq comming..., irq nest:%d\n", rt_interrupt_nest));
level = rt_hw_interrupt_disable();
@ -62,8 +60,20 @@ void rt_interrupt_leave()
level = rt_hw_interrupt_disable();
rt_interrupt_nest --;
rt_hw_interrupt_enable(level);
}
RT_DEBUG_REENT_OUT
/**
* This function will return the nest of interrupt.
*
* User application can invoke this function to get whenther current
* context is interrupt context.
*
* @return the number of nested interrupts.
*/
rt_uint8_t rt_interrupt_get_nest(void)
{
return rt_interrupt_nest;
}
/*@}*/

View File

@ -27,7 +27,7 @@
#ifndef RT_USING_NEWLIB
/* global errno in RT-Thread*/
int errno;
volatile int errno;
#else
#include <errno.h>
#endif
@ -44,7 +44,7 @@ rt_err_t rt_get_errno(void)
{
rt_thread_t tid;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
tid = rt_thread_self();
if (tid == RT_NULL) return errno;
@ -61,7 +61,7 @@ void rt_set_errno(rt_err_t error)
{
rt_thread_t tid;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
tid = rt_thread_self();
if (tid == RT_NULL) { errno = error; return; }

View File

@ -140,8 +140,6 @@ static void plug_holes(struct heap_mem *mem)
struct heap_mem *nmem;
struct heap_mem *pmem;
RT_DEBUG_NOT_REENT
RT_ASSERT((rt_uint8_t *)mem >= heap_ptr);
RT_ASSERT((rt_uint8_t *)mem < (rt_uint8_t *)heap_end);
RT_ASSERT(mem->used == 0);
@ -188,7 +186,7 @@ void rt_system_heap_init(void* begin_addr, void* end_addr)
rt_uint32_t begin_align = RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
rt_uint32_t end_align = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_ALIGN_SIZE);
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* alignment addr */
if((end_align > (2 * SIZEOF_STRUCT_MEM) ) &&
@ -245,16 +243,14 @@ void *rt_malloc(rt_size_t size)
rt_size_t ptr, ptr2;
struct heap_mem *mem, *mem2;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
if (size == 0) return RT_NULL;
#if RT_DEBUG_MEM
if (size != RT_ALIGN(size, RT_ALIGN_SIZE))
rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE));
RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE)));
else
rt_kprintf("malloc size %d\n", size);
#endif
RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d\n", size));
/* alignment size */
size = RT_ALIGN(size, RT_ALIGN_SIZE);
@ -351,9 +347,7 @@ void *rt_malloc(rt_size_t size)
(rt_uint32_t)((rt_uint8_t*)mem + SIZEOF_STRUCT_MEM),
(rt_uint32_t)(mem->next - ((rt_uint8_t*)mem - heap_ptr))));
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_malloc_hook,(rt_uint8_t *)mem + SIZEOF_STRUCT_MEM,size);
#endif
RT_OBJECT_HOOK_CALL(rt_malloc_hook, (((void*)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM)), size));
/* return the memory data except mem struct */
return (rt_uint8_t *)mem + SIZEOF_STRUCT_MEM;
}
@ -378,7 +372,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
struct heap_mem *mem, *mem2;
void* nmem;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* alignment size */
newsize = RT_ALIGN(newsize, RT_ALIGN_SIZE);
@ -467,7 +461,7 @@ void *rt_calloc(rt_size_t count, rt_size_t size)
{
void *p;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate 'count' objects of size 'size' */
p = rt_malloc(count * size);
@ -488,16 +482,14 @@ void rt_free(void *rmem)
{
struct heap_mem *mem;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
if (rmem == RT_NULL) return;
RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE-1)) == 0);
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_free_hook,rmem);
#endif
RT_OBJECT_HOOK_CALL(rt_free_hook, (rmem));
if ((rt_uint8_t *)rmem < (rt_uint8_t *)heap_ptr || (rt_uint8_t *)rmem >= (rt_uint8_t *)heap_end)
{

View File

@ -182,7 +182,7 @@ rt_mp_t rt_mp_create(const char* name, rt_size_t block_count, rt_size_t block_si
struct rt_mempool* mp;
register rt_base_t offset;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
mp = (struct rt_mempool*)rt_object_allocate(RT_Object_Class_MemPool, name);
@ -237,7 +237,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
struct rt_thread* thread;
register rt_ubase_t temp;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* parameter check */
RT_ASSERT(mp != RT_NULL);
@ -325,7 +325,7 @@ void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time)
}
else
{
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* get current thread */
thread = rt_thread_self();
@ -368,9 +368,7 @@ void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time)
/* enable interrupt */
rt_hw_interrupt_enable(level);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_mp_alloc_hook,mp, (rt_uint8_t*)(block_ptr + sizeof(rt_uint8_t*)));
#endif
RT_OBJECT_HOOK_CALL(rt_mp_alloc_hook, (mp, (rt_uint8_t*)(block_ptr + sizeof(rt_uint8_t*))));
return (rt_uint8_t*)(block_ptr + sizeof(rt_uint8_t*));
}
@ -392,9 +390,7 @@ void rt_mp_free (void *block)
block_ptr = (rt_uint8_t**)((rt_uint8_t*)block - sizeof(rt_uint8_t*));
mp = (struct rt_mempool*) *block_ptr;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_mp_free_hook,mp, block);
#endif
RT_OBJECT_HOOK_CALL(rt_mp_free_hook, (mp, block));
/* disable interrupt */
level = rt_hw_interrupt_disable();

View File

@ -264,7 +264,7 @@ rt_module_t rt_module_load(const char* name, void* module_ptr)
rt_bool_t linked = RT_FALSE;
rt_uint32_t index, module_size = 0;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
rt_kprintf("rt_module_load: %s ,", name);
@ -484,7 +484,7 @@ rt_module_t rt_module_open(const char* filename)
struct stat s;
char *buffer, *offset_ptr;;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* check parameters */
RT_ASSERT(filename != RT_NULL);
@ -555,7 +555,7 @@ rt_err_t rt_module_unload(rt_module_t module)
struct rt_object* object;
struct rt_list_node *list;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
rt_kprintf("rt_module_unload: %s\n", module->parent.name);
@ -774,7 +774,7 @@ rt_module_t rt_module_find(const char* name)
extern struct rt_object_information rt_object_container[];
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* enter critical */
rt_enter_critical();
@ -807,7 +807,7 @@ static struct rt_mem_head *morepage(rt_size_t nu)
struct rt_mem_head *up;
struct rt_module_page *node;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
RT_ASSERT (nu != 0);
@ -840,7 +840,7 @@ void *rt_module_malloc(rt_size_t size)
struct rt_mem_head **prev;
rt_size_t nunits;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
nunits = (size + sizeof(struct rt_mem_head) -1)/sizeof(struct rt_mem_head) + 1;
@ -910,7 +910,7 @@ void rt_module_free(rt_module_t module, void *addr)
struct rt_mem_head *b, *n;
struct rt_mem_head **prev;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
RT_ASSERT(addr);
RT_ASSERT((((rt_uint32_t)addr) & (sizeof(struct rt_mem_head) -1)) == 0);
@ -961,7 +961,7 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
struct rt_mem_head *b, *p, *prev, *tmpp;
rt_size_t nunits;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
if (!ptr) return rt_module_malloc(size);
if (size == 0)

View File

@ -206,6 +206,17 @@ void rt_system_object_init(void)
*/
/*@{*/
/**
* This function will return the specified type of object information.
*
* @param type the type of object
* @return the object type information or RT_NULL
*/
struct rt_object_information *rt_object_get_information(enum rt_object_class_type type)
{
return &rt_object_container[type];
}
/**
* This function will initialize an object and add it to object system management.
*
@ -238,9 +249,7 @@ void rt_object_init(struct rt_object* object, enum rt_object_class_type type, co
object->name[temp] = name[temp];
}
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_attach_hook,object);
#endif
RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));
/* lock interrupt */
temp = rt_hw_interrupt_disable();
@ -265,9 +274,7 @@ void rt_object_detach(rt_object_t object)
/* object check */
RT_ASSERT(object != RT_NULL);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_detach_hook,object);
#endif
RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object));
/* lock interrupt */
temp = rt_hw_interrupt_disable();
@ -294,7 +301,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
register rt_base_t temp;
struct rt_object_information* information;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
#ifdef RT_USING_MODULE
/* get module object information, module object should be managed by kernel object container */
@ -334,9 +341,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
object->name[temp] = name[temp];
}
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_attach_hook,object);
#endif
RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));
/* lock interrupt */
temp = rt_hw_interrupt_disable();
@ -364,9 +369,7 @@ void rt_object_delete(rt_object_t object)
RT_ASSERT(object != RT_NULL);
RT_ASSERT(!(object->type & RT_Object_Class_Static));
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_detach_hook,object);
#endif
RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object));
/* lock interrupt */
temp = rt_hw_interrupt_disable();

View File

@ -273,9 +273,7 @@ void rt_schedule()
(rt_module_t)rt_current_thread->module_id : RT_NULL);
#endif
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_scheduler_hook,from_thread, to_thread);
#endif
RT_OBJECT_HOOK_CALL(rt_scheduler_hook, (from_thread, to_thread));
/* switch to new thread */
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
@ -328,13 +326,12 @@ void rt_schedule_insert_thread(struct rt_thread* thread)
&(thread->tlist));
/* set priority mask */
#if RT_DEBUG_SCHEDULER
#if RT_THREAD_PRIORITY_MAX <= 32
rt_kprintf("insert thread[%s], the priority: %d\n", thread->name, thread->current_priority);
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%s], the priority: %d\n",
thread->name, thread->current_priority));
#else
rt_kprintf("insert thread[%s], the priority: %d 0x%x %d\n", thread->name, thread->number, thread->number_mask, thread->high_mask);
#endif
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%s], the priority: %d 0x%x %d\n",
thread->name, thread->number, thread->number_mask, thread->high_mask));
#endif
#if RT_THREAD_PRIORITY_MAX > 32
@ -362,14 +359,12 @@ void rt_schedule_remove_thread(struct rt_thread* thread)
/* disable interrupt */
temp = rt_hw_interrupt_disable();
#if RT_DEBUG_SCHEDULER
#if RT_THREAD_PRIORITY_MAX <= 32
rt_kprintf("remove thread[%s], the priority: %d\n", thread->name, thread->current_priority);
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("remove thread[%s], the priority: %d\n",
thread->name, thread->current_priority));
#else
rt_kprintf("remove thread[%s], the priority: %d 0x%x %d\n", thread->name, thread->number,
thread->number_mask, thread->high_mask);
#endif
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("remove thread[%s], the priority: %d 0x%x %d\n",
thread->name, thread->number, thread->number_mask, thread->high_mask));
#endif
/* remove thread from ready list */

View File

@ -337,7 +337,7 @@ void rt_system_heap_init(void *begin_addr, void* end_addr)
{
rt_uint32_t limsize, npages;
RT_DEBUG_NOT_REENT
RT_DEBUG_NOT_IN_INTERRUPT;
/* align begin and end addr to page */
heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE);
@ -681,9 +681,7 @@ void *rt_malloc(rt_size_t size)
done:
rt_sem_release(&heap_sem);
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_malloc_hook,(char*)chunk, size);
#endif
RT_OBJECT_HOOK_CALL(rt_malloc_hook, ((char*)chunk, size));
return chunk;
@ -797,9 +795,7 @@ void rt_free(void *ptr)
/* free a RT_NULL pointer */
if (ptr == RT_NULL) return ;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_free_hook,ptr);
#endif
RT_OBJECT_HOOK_CALL(rt_free_hook, (ptr));
#ifdef RT_USING_MODULE
if(rt_module_self() != RT_NULL)

View File

@ -210,9 +210,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
RT_ASSERT(timer != RT_NULL);
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) return -RT_ERROR;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_take_hook,&(timer->parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent)));
/* disable interrupt */
level = rt_hw_interrupt_disable();
@ -277,9 +275,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
RT_ASSERT(timer != RT_NULL);
if(!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)) return -RT_ERROR;
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_object_put_hook,&(timer->parent));
#endif
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(timer->parent)));
/* disable interrupt */
level = rt_hw_interrupt_disable();
@ -364,22 +360,14 @@ void rt_timer_check(void)
*/
if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
{
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_timer_timeout_hook,t);
#endif
RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));
/* remove timer from timer list firstly */
rt_list_remove(&(t->list));
/* Timeout function called while interrupt is disabled, reentant function
is a must */
RT_DEBUG_REENT_IN
/* call timeout function */
t->timeout_func(t->parameter);
RT_DEBUG_REENT_OUT
/* re-get tick */
current_tick = rt_tick_get();
@ -455,9 +443,8 @@ void rt_soft_timer_check()
*/
if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
{
#ifdef RT_USING_HOOK
RT_OBJECT_HOOK_CALL2(rt_timer_timeout_hook,t);
#endif
RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));
/* move node to the next */
n = n->next;