From 214e44c3f9d79e34719cd9cef5e2fc596a693d47 Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Tue, 13 Jul 2010 07:36:37 +0000 Subject: fix down alignment issue; fix the maximal number of rt_scheduler_lock_nest issue; fix rt_tick_from_millisecond issue. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@790 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- src/mem.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/mem.c') diff --git a/src/mem.c b/src/mem.c index cd09bc1994..ac091c6f76 100644 --- a/src/mem.c +++ b/src/mem.c @@ -12,6 +12,7 @@ * 2008-7-12 Bernard the first version * 2010-06-09 Bernard fix the end stub of heap * fix memory check in rt_realloc function + * 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca */ /* @@ -170,7 +171,7 @@ void rt_system_heap_init(void* begin_addr, void* end_addr) begin_addr = (void*)RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE); /* calculate the aligned memory size */ - mem_size_aligned = RT_ALIGN((rt_uint32_t)end_addr - (rt_uint32_t)begin_addr, RT_ALIGN_SIZE) - 2 * SIZEOF_STRUCT_MEM; + mem_size_aligned = RT_ALIGN_DOWN((rt_uint32_t)end_addr - (rt_uint32_t)begin_addr, RT_ALIGN_SIZE) - 2 * SIZEOF_STRUCT_MEM; /* point to begin address of heap */ heap_ptr = begin_addr; @@ -220,7 +221,10 @@ void *rt_malloc(rt_size_t size) if (size == 0) return RT_NULL; #ifdef RT_MEM_DEBUG - rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE)); + 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)); + else + rt_kprintf("malloc size %d\n", size); #endif /* alignment size */ @@ -351,7 +355,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize) if (newsize > mem_size_aligned) { #ifdef RT_MEM_DEBUG - rt_kprintf("no memory\n"); + rt_kprintf("realloc: out of memory\n"); #endif return RT_NULL; } @@ -498,15 +502,15 @@ void rt_free(void *rmem) rt_sem_release(&heap_sem); } -#ifdef RT_MEM_STATS -void rt_memory_info(rt_uint32_t *total, - rt_uint32_t *used, - rt_uint32_t *max_used) -{ - if (total != RT_NULL) *total = mem_size_aligned; - if (used != RT_NULL) *used = used_mem; - if (max_used != RT_NULL) *max_used = max_mem; -} +#ifdef RT_MEM_STATS +void rt_memory_info(rt_uint32_t *total, + rt_uint32_t *used, + rt_uint32_t *max_used) +{ + if (total != RT_NULL) *total = mem_size_aligned; + if (used != RT_NULL) *used = used_mem; + if (max_used != RT_NULL) *max_used = max_mem; +} #ifdef RT_USING_FINSH #include -- cgit v1.3.1