提交 4952adb4 编写于 作者: D dzzxzz@gmail.com

fixed coding style in src/slab.c

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2527 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 ff658411
......@@ -216,7 +216,8 @@ struct memusage
rt_uint32_t size:30; /* pages allocated or offset from zone */
};
static struct memusage *memusage = RT_NULL;
#define btokup(addr) (&memusage[((rt_uint32_t)(addr) - heap_start) >> RT_MM_PAGE_BITS])
#define btokup(addr) \
(&memusage[((rt_uint32_t)(addr) - heap_start) >> RT_MM_PAGE_BITS])
static rt_uint32_t heap_start, heap_end;
......@@ -399,13 +400,15 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
*/
rt_inline int zoneindex(rt_uint32_t *bytes)
{
rt_uint32_t n = (rt_uint32_t)*bytes; /* unsigned for shift opt */
/* unsigned for shift opt */
rt_uint32_t n = (rt_uint32_t)*bytes;
if (n < 128)
{
*bytes = n = (n + 7) & ~7;
return(n / 8 - 1); /* 8 byte chunks, 16 zones */
/* 8 byte chunks, 16 zones */
return(n / 8 - 1);
}
if (n < 256)
{
......@@ -718,7 +721,8 @@ void *rt_realloc(void *ptr, rt_size_t size)
}
else if (kup->type == PAGE_TYPE_SMALL)
{
z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) - kup->size * RT_MM_PAGE_SIZE);
z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) -
kup->size * RT_MM_PAGE_SIZE);
RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC);
zoneindex(&size);
......@@ -771,7 +775,7 @@ void *rt_calloc(rt_size_t count, rt_size_t size)
RTM_EXPORT(rt_calloc);
/**
* This function will release the previously allocated memory block by rt_malloc.
* This function will release the previous allocated memory block by rt_malloc.
* The released memory block is taken back to system heap.
*
* @param ptr the address of memory which will be released
......@@ -840,7 +844,8 @@ void rt_free(void *ptr)
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
/* zone case. get out zone. */
z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) - kup->size * RT_MM_PAGE_SIZE);
z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) -
kup->size * RT_MM_PAGE_SIZE);
RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC);
chunk = (slab_chunk *)ptr;
......@@ -867,7 +872,8 @@ void rt_free(void *ptr)
* this code can be called from an IPI callback, do *NOT* try to mess
* with kernel_map here. Hysteresis will be performed at malloc() time.
*/
if (z->z_nfree == z->z_nmax && (z->z_next || zone_array[z->z_zoneindex] != z))
if (z->z_nfree == z->z_nmax &&
(z->z_next || zone_array[z->z_zoneindex] != z))
{
slab_zone **pz;
......@@ -920,7 +926,9 @@ void rt_free(void *ptr)
RTM_EXPORT(rt_free);
#ifdef RT_MEM_STATS
void rt_memory_info(rt_uint32_t *total, rt_uint32_t *used, rt_uint32_t *max_used)
void rt_memory_info(rt_uint32_t *total,
rt_uint32_t *used,
rt_uint32_t *max_used)
{
if (total != RT_NULL)
*total = heap_end - heap_start;
......@@ -934,6 +942,7 @@ void rt_memory_info(rt_uint32_t *total, rt_uint32_t *used, rt_uint32_t *max_used
#ifdef RT_USING_FINSH
#include <finsh.h>
void list_mem(void)
{
rt_kprintf("total memory: %d\n", heap_end - heap_start);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册