提交 9975b31d 编写于 作者: B bernard.xiong@gmail.com

fix align issue in rt_mp_init and rt_mp_create function.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2007 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 e19102ed
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca * 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
* 2010-10-26 yi.qiu add module support in rt_mp_delete * 2010-10-26 yi.qiu add module support in rt_mp_delete
* 2011-01-24 Bernard add object allocation check. * 2011-01-24 Bernard add object allocation check.
* 2012-03-22 Bernard fix align issue in rt_mp_init and rt_mp_create.
*/ */
#include <rthw.h> #include <rthw.h>
...@@ -85,24 +86,26 @@ rt_err_t rt_mp_init(struct rt_mempool *mp, const char *name, void *start, rt_siz ...@@ -85,24 +86,26 @@ rt_err_t rt_mp_init(struct rt_mempool *mp, const char *name, void *start, rt_siz
/* parameter check */ /* parameter check */
RT_ASSERT(mp != RT_NULL); RT_ASSERT(mp != RT_NULL);
/* init object */ /* initialize object */
rt_object_init(&(mp->parent), RT_Object_Class_MemPool, name); rt_object_init(&(mp->parent), RT_Object_Class_MemPool, name);
/* init memory pool */ /* initialize memory pool */
mp->start_address = start; mp->start_address = start;
mp->size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE); mp->size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE);
/* align the block size */
block_size = RT_ALIGN(block_size, RT_ALIGN_SIZE);
mp->block_size = block_size; mp->block_size = block_size;
/* align to align size byte */ /* align to align size byte */
mp->block_total_count = mp->size / (mp->block_size + sizeof(rt_uint8_t *)); mp->block_total_count = mp->size / (mp->block_size + sizeof(rt_uint8_t *));
mp->block_free_count = mp->block_total_count; mp->block_free_count = mp->block_total_count;
/* init suspended thread list */ /* initialize suspended thread list */
rt_list_init(&(mp->suspend_thread)); rt_list_init(&(mp->suspend_thread));
mp->suspend_thread_count = 0; mp->suspend_thread_count = 0;
/* init free block list */ /* initialize free block list */
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 ++)
{ {
...@@ -132,7 +135,7 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp) ...@@ -132,7 +135,7 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp)
/* parameter check */ /* parameter check */
RT_ASSERT(mp != RT_NULL); RT_ASSERT(mp != RT_NULL);
/* wakeup all suspended threads */ /* wake up all suspended threads */
while (!rt_list_isempty(&(mp->suspend_thread))) while (!rt_list_isempty(&(mp->suspend_thread)))
{ {
/* disable interrupt */ /* disable interrupt */
...@@ -186,8 +189,9 @@ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_si ...@@ -186,8 +189,9 @@ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_si
if (mp == RT_NULL) if (mp == RT_NULL)
return RT_NULL; /* allocate object failed */ return RT_NULL; /* allocate object failed */
/* init memory pool */ /* initialize memory pool */
mp->block_size = RT_ALIGN(block_size, RT_ALIGN_SIZE); block_size = RT_ALIGN(block_size, RT_ALIGN_SIZE);
mp->block_size = block_size;
mp->size = (block_size + sizeof(rt_uint8_t *)) * block_count; mp->size = (block_size + sizeof(rt_uint8_t *)) * block_count;
/* allocate memory */ /* allocate memory */
...@@ -203,11 +207,11 @@ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_si ...@@ -203,11 +207,11 @@ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_si
mp->block_total_count = block_count; mp->block_total_count = block_count;
mp->block_free_count = mp->block_total_count; mp->block_free_count = mp->block_total_count;
/* init suspended thread list */ /* initialize suspended thread list */
rt_list_init(&(mp->suspend_thread)); rt_list_init(&(mp->suspend_thread));
mp->suspend_thread_count = 0; mp->suspend_thread_count = 0;
/* init free block list */ /* initialize free block list */
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 ++)
{ {
...@@ -239,7 +243,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp) ...@@ -239,7 +243,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
/* parameter check */ /* parameter check */
RT_ASSERT(mp != RT_NULL); RT_ASSERT(mp != RT_NULL);
/* wakeup all suspended threads */ /* wake up all suspended threads */
while (!rt_list_isempty(&(mp->suspend_thread))) while (!rt_list_isempty(&(mp->suspend_thread)))
{ {
/* disable interrupt */ /* disable interrupt */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册