fixed coding style in src/slab.c
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2527 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
ff65841125
commit
4952adb4f0
25
src/slab.c
25
src/slab.c
|
@ -216,7 +216,8 @@ struct memusage
|
||||||
rt_uint32_t size:30; /* pages allocated or offset from zone */
|
rt_uint32_t size:30; /* pages allocated or offset from zone */
|
||||||
};
|
};
|
||||||
static struct memusage *memusage = RT_NULL;
|
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;
|
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_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)
|
if (n < 128)
|
||||||
{
|
{
|
||||||
*bytes = n = (n + 7) & ~7;
|
*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)
|
if (n < 256)
|
||||||
{
|
{
|
||||||
|
@ -718,7 +721,8 @@ void *rt_realloc(void *ptr, rt_size_t size)
|
||||||
}
|
}
|
||||||
else if (kup->type == PAGE_TYPE_SMALL)
|
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);
|
RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC);
|
||||||
|
|
||||||
zoneindex(&size);
|
zoneindex(&size);
|
||||||
|
@ -771,7 +775,7 @@ void *rt_calloc(rt_size_t count, rt_size_t size)
|
||||||
RTM_EXPORT(rt_calloc);
|
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.
|
* The released memory block is taken back to system heap.
|
||||||
*
|
*
|
||||||
* @param ptr the address of memory which will be released
|
* @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);
|
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
|
||||||
|
|
||||||
/* zone case. get out zone. */
|
/* 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);
|
RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC);
|
||||||
|
|
||||||
chunk = (slab_chunk *)ptr;
|
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
|
* 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.
|
* 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;
|
slab_zone **pz;
|
||||||
|
|
||||||
|
@ -920,7 +926,9 @@ void rt_free(void *ptr)
|
||||||
RTM_EXPORT(rt_free);
|
RTM_EXPORT(rt_free);
|
||||||
|
|
||||||
#ifdef RT_MEM_STATS
|
#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)
|
if (total != RT_NULL)
|
||||||
*total = heap_end - heap_start;
|
*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
|
#ifdef RT_USING_FINSH
|
||||||
#include <finsh.h>
|
#include <finsh.h>
|
||||||
|
|
||||||
void list_mem(void)
|
void list_mem(void)
|
||||||
{
|
{
|
||||||
rt_kprintf("total memory: %d\n", heap_end - heap_start);
|
rt_kprintf("total memory: %d\n", heap_end - heap_start);
|
||||||
|
|
Loading…
Reference in New Issue