fixed the coding style in memheap.c
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2569 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
d5531c6054
commit
965c25d3a4
|
@ -142,7 +142,8 @@ void *rt_memheap_alloc(struct rt_memheap *heap, rt_uint32_t size)
|
|||
if (size < RT_MEMHEAP_MINIALLOC)
|
||||
size = RT_MEMHEAP_MINIALLOC;
|
||||
|
||||
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("allocate %d on heap:%8.*s", size, RT_NAME_MAX, heap->parent.name));
|
||||
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("allocate %d on heap:%8.*s",
|
||||
size, RT_NAME_MAX, heap->parent.name));
|
||||
|
||||
if (size < heap->available_size)
|
||||
{
|
||||
|
@ -377,7 +378,10 @@ static struct rt_memheap _heap;
|
|||
void rt_system_heap_init(void *begin_addr, void *end_addr)
|
||||
{
|
||||
/* initialize a default heap in the system */
|
||||
rt_memheap_init(&_heap, "heap", begin_addr, (rt_uint32_t)end_addr - (rt_uint32_t)begin_addr);
|
||||
rt_memheap_init(&_heap,
|
||||
"heap",
|
||||
begin_addr,
|
||||
(rt_uint32_t)end_addr - (rt_uint32_t)begin_addr);
|
||||
}
|
||||
|
||||
void *rt_malloc(rt_size_t size)
|
||||
|
@ -396,16 +400,20 @@ void *rt_malloc(rt_size_t size)
|
|||
|
||||
/* try to allocate on other memory heap */
|
||||
information = &rt_object_container[RT_Object_Class_MemHeap];
|
||||
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
|
||||
for (node = information->object_list.next;
|
||||
node != &(information->object_list);
|
||||
node = node->next)
|
||||
{
|
||||
object = rt_list_entry(node, struct rt_object, list);
|
||||
heap = (struct rt_memheap *)object;
|
||||
|
||||
/* not allocate in the default system heap */
|
||||
if (heap == &_heap) continue;
|
||||
if (heap == &_heap)
|
||||
continue;
|
||||
|
||||
ptr = rt_memheap_alloc(heap, size);
|
||||
if (ptr != RT_NULL) break;
|
||||
if (ptr != RT_NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -440,13 +448,15 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
|
|||
if (newsize == 0)
|
||||
{
|
||||
rt_free(rmem);
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* get old memory item */
|
||||
header_ptr = (struct rt_memheap_item *)((rt_uint8_t *)rmem - RT_MEMHEAP_SIZE);
|
||||
size = MEMITEM_SIZE(header_ptr);
|
||||
if (newsize > size || newsize < size - RT_MEMHEAP_SIZE) /* re-allocate memory */
|
||||
/* re-allocate memory */
|
||||
if (newsize > size || newsize < size - RT_MEMHEAP_SIZE)
|
||||
{
|
||||
/* re-allocate a memory block */
|
||||
nmem = (void*)rt_malloc(newsize);
|
||||
|
|
Loading…
Reference in New Issue