fixed coding style in src/mempool.c

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2525 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
dzzxzz@gmail.com 2012-12-25 09:10:39 +00:00
parent dc5a16861a
commit dec45642fb
1 changed files with 241 additions and 224 deletions

View File

@ -67,8 +67,8 @@ void rt_mp_free_sethook(void (*hook)(struct rt_mempool *mp, void *block))
/*@{*/ /*@{*/
/** /**
* This function will initialize a memory pool object, normally which is used for * This function will initialize a memory pool object, normally which is used
* static object. * for static object.
* *
* @param mp the memory pool object * @param mp the memory pool object
* @param name the name of memory pool * @param name the name of memory pool
@ -78,7 +78,11 @@ void rt_mp_free_sethook(void (*hook)(struct rt_mempool *mp, void *block))
* *
* @return RT_EOK * @return RT_EOK
*/ */
rt_err_t rt_mp_init(struct rt_mempool *mp, const char *name, void *start, rt_size_t size, rt_size_t block_size) rt_err_t rt_mp_init(struct rt_mempool *mp,
const char *name,
void *start,
rt_size_t size,
rt_size_t block_size)
{ {
rt_uint8_t *block_ptr; rt_uint8_t *block_ptr;
register rt_base_t offset; register rt_base_t offset;
@ -109,11 +113,12 @@ rt_err_t rt_mp_init(struct rt_mempool *mp, const char *name, void *start, rt_siz
block_ptr = (rt_uint8_t *)mp->start_address; block_ptr = (rt_uint8_t *)mp->start_address;
for (offset = 0; offset < mp->block_total_count; offset ++) for (offset = 0; offset < mp->block_total_count; offset ++)
{ {
*(rt_uint8_t **)(block_ptr + offset * (block_size + sizeof(rt_uint8_t *))) *(rt_uint8_t **)(block_ptr + offset * (block_size + sizeof(rt_uint8_t *))) =
= (rt_uint8_t *)(block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t *))); (rt_uint8_t *)(block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t *)));
} }
*(rt_uint8_t **)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t *))) = RT_NULL; *(rt_uint8_t **)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t *))) =
RT_NULL;
mp->block_list = block_ptr; mp->block_list = block_ptr;
@ -149,8 +154,8 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp)
/* /*
* resume thread * resume thread
* In rt_thread_resume function, it will remove current thread from suspend * In rt_thread_resume function, it will remove current thread from
* list * suspend list
*/ */
rt_thread_resume(thread); rt_thread_resume(thread);
@ -170,7 +175,8 @@ RTM_EXPORT(rt_mp_detach);
#ifdef RT_USING_HEAP #ifdef RT_USING_HEAP
/** /**
* This function will create a mempool object and allocate the memory pool from heap. * This function will create a mempool object and allocate the memory pool from
* heap.
* *
* @param name the name of memory pool * @param name the name of memory pool
* @param block_count the count of blocks in memory pool * @param block_count the count of blocks in memory pool
@ -178,7 +184,9 @@ RTM_EXPORT(rt_mp_detach);
* *
* @return the created mempool object * @return the created mempool object
*/ */
rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_size) rt_mp_t rt_mp_create(const char *name,
rt_size_t block_count,
rt_size_t block_size)
{ {
rt_uint8_t *block_ptr; rt_uint8_t *block_ptr;
struct rt_mempool *mp; struct rt_mempool *mp;
@ -188,8 +196,9 @@ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_si
/* allocate object */ /* allocate object */
mp = (struct rt_mempool *)rt_object_allocate(RT_Object_Class_MemPool, name); mp = (struct rt_mempool *)rt_object_allocate(RT_Object_Class_MemPool, name);
/* allocate object failed */
if (mp == RT_NULL) if (mp == RT_NULL)
return RT_NULL; /* allocate object failed */ return RT_NULL;
/* initialize memory pool */ /* initialize memory pool */
block_size = RT_ALIGN(block_size, RT_ALIGN_SIZE); block_size = RT_ALIGN(block_size, RT_ALIGN_SIZE);
@ -197,7 +206,8 @@ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_si
mp->size = (block_size + sizeof(rt_uint8_t *)) * block_count; mp->size = (block_size + sizeof(rt_uint8_t *)) * block_count;
/* allocate memory */ /* allocate memory */
mp->start_address = rt_malloc((block_size + sizeof(rt_uint8_t *)) * block_count); mp->start_address = rt_malloc((block_size + sizeof(rt_uint8_t *)) *
block_count);
if (mp->start_address == RT_NULL) if (mp->start_address == RT_NULL)
{ {
/* no memory, delete memory pool object */ /* no memory, delete memory pool object */
@ -221,7 +231,8 @@ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_si
= block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t *)); = block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t *));
} }
*(rt_uint8_t **)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t *))) = RT_NULL; *(rt_uint8_t **)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t *)))
= RT_NULL;
mp->block_list = block_ptr; mp->block_list = block_ptr;
@ -259,8 +270,8 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
/* /*
* resume thread * resume thread
* In rt_thread_resume function, it will remove current thread from suspend * In rt_thread_resume function, it will remove current thread from
* list * suspend list
*/ */
rt_thread_resume(thread); rt_thread_resume(thread);
@ -325,6 +336,7 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
{ {
/* enable interrupt */ /* enable interrupt */
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
return RT_NULL; return RT_NULL;
} }
else else
@ -342,7 +354,9 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
if (time > 0) if (time > 0)
{ {
/* init thread timer and start it */ /* init thread timer and start it */
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &time); rt_timer_control(&(thread->thread_timer),
RT_TIMER_CTRL_SET_TIME,
&time);
rt_timer_start(&(thread->thread_timer)); rt_timer_start(&(thread->thread_timer));
} }
@ -373,7 +387,8 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
/* enable interrupt */ /* enable interrupt */
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
RT_OBJECT_HOOK_CALL(rt_mp_alloc_hook, (mp, (rt_uint8_t *)(block_ptr + sizeof(rt_uint8_t *)))); 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 *)); return (rt_uint8_t *)(block_ptr + sizeof(rt_uint8_t *));
} }
@ -410,7 +425,9 @@ void rt_mp_free(void *block)
if (mp->suspend_thread_count > 0) if (mp->suspend_thread_count > 0)
{ {
/* get the suspended thread */ /* get the suspended thread */
thread = rt_list_entry(mp->suspend_thread.next, struct rt_thread, tlist); thread = rt_list_entry(mp->suspend_thread.next,
struct rt_thread,
tlist);
/* set error */ /* set error */
thread->error = RT_EOK; thread->error = RT_EOK;