rewrite module memory allocator

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1618 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
qiuyiuestc@gmail.com
2011-07-04 23:48:07 +00:00
parent 3bc0dd4a82
commit cea21370a4
9 changed files with 653 additions and 427 deletions
+2 -2
View File
@@ -759,8 +759,8 @@ struct rt_module
/* module memory allocator */
void* mem_list; /**< module's free memory list */
rt_list_t page_list; /**< module's using page list */
rt_mp_t mpool; /**< module's memory pool */
void* page_array; /**< module's using pages */
rt_uint32_t page_cnt; /**< module's using pages count */
rt_uint32_t nsym; /**< number of symbol in the module */
struct rt_module_symtab *symtab; /**< module symbol table */
+6
View File
@@ -317,6 +317,12 @@ void rt_module_free(rt_module_t module, void *addr);
rt_module_t rt_module_self (void);
rt_err_t rt_module_set (rt_module_t module);
rt_module_t rt_module_find(const char* name);
#ifdef RT_USING_HOOK
void rt_module_load_sethook(void (*hook)(rt_module_t module));
void rt_module_unload_sethook(void (*hook)(rt_module_t module));
#endif
#endif
/*@}*/
+3 -3
View File
@@ -115,7 +115,7 @@ void rt_thread_idle_excute(void)
rt_hw_interrupt_enable(lock);
#ifdef RT_USING_HEAP
#ifdef RT_USING_MODULE
#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
/* the thread belongs to an application module */
if(thread->flags & RT_OBJECT_FLAG_MODULE)
rt_module_free((rt_module_t)thread->module_id, thread->stack_addr);
@@ -125,6 +125,7 @@ void rt_thread_idle_excute(void)
rt_free(thread->stack_addr);
/* delete thread object */
rt_object_delete((rt_object_t)thread);
#endif
#ifdef RT_USING_MODULE
if(module != RT_NULL)
@@ -138,8 +139,7 @@ void rt_thread_idle_excute(void)
}
/* unload module */
if(module->nref == 0) rt_module_unload(module);
#endif
if(module->nref == 0) rt_module_unload(module);
#endif
}
}
+2 -2
View File
@@ -1286,7 +1286,7 @@ rt_err_t rt_mb_delete (rt_mailbox_t mb)
/* also resume all mailbox private suspended thread */
rt_ipc_list_resume_all(&(mb->suspend_sender_thread));
#ifdef RT_USING_MODULE
#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
/* the mb object belongs to an application module */
if(mb->parent.parent.flag & RT_OBJECT_FLAG_MODULE)
rt_module_free(mb->parent.parent.module_id, mb->msg_pool);
@@ -1761,7 +1761,7 @@ rt_err_t rt_mq_delete (rt_mq_t mq)
/* resume all suspended thread */
rt_ipc_list_resume_all(&(mq->parent.suspend_thread));
#ifdef RT_USING_MODULE
#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
/* the mq object belongs to an application module */
if(mq->parent.parent.flag & RT_OBJECT_FLAG_MODULE)
rt_module_free(mq->parent.parent.module_id, mq->msg_pool);
+1 -1
View File
@@ -267,7 +267,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
rt_hw_interrupt_enable(temp);
}
#ifdef RT_USING_MODULE
#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
/* the mp object belongs to an application module */
if(mp->parent.flag & RT_OBJECT_FLAG_MODULE)
rt_module_free(mp->parent.module_id, mp->start_address);
+357 -113
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -340,7 +340,7 @@ void rt_object_delete(rt_object_t object)
/* unlock interrupt */
rt_hw_interrupt_enable(temp);
#ifdef RT_USING_MODULE
#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
if(object->flag & RT_OBJECT_FLAG_MODULE)
rt_module_free((rt_module_t)object->module_id, object);
else
+268 -259
View File
File diff suppressed because it is too large Load Diff
+13 -46
View File
@@ -256,6 +256,12 @@ void *rt_page_alloc(rt_size_t npages)
break;
}
}
#ifdef RT_MEM_STATS
used_mem += npages * RT_MM_PAGE_SIZE;
if (used_mem > max_mem) max_mem = used_mem;
#endif
/* unlock heap */
rt_sem_release(&heap_sem);
@@ -275,6 +281,13 @@ void rt_page_free(void *addr, rt_size_t npages)
/* lock heap */
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
/* update memory usage */
#ifdef RT_MEM_STATS
if(rt_page_list != RT_NULL)
used_mem -= npages * RT_MM_PAGE_SIZE;
#endif
for (prev = &rt_page_list; (b = *prev) != RT_NULL; prev = &(b->next))
{
RT_ASSERT(b->page > 0);
@@ -443,52 +456,6 @@ rt_inline int zoneindex(rt_uint32_t *bytes)
/*@{*/
/*
* This function will allocate the numbers page with specified size
* in page memory.
*
* @param size the size of memory to be allocated.
* @note this function is used for RT-Thread Application Module
*/
void *rt_malloc_page(rt_size_t npages)
{
void* chunk;
chunk = rt_page_alloc(npages);
if (chunk == RT_NULL) return RT_NULL;
/* update memory usage */
#ifdef RT_MEM_STATS
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
used_mem += npages * RT_MM_PAGE_SIZE;
if (used_mem > max_mem) max_mem = used_mem;
rt_sem_release(&heap_sem);
#endif
return chunk;
}
/*
* This function will release the previously allocated memory page
* by rt_malloc_page.
*
* @param page_ptr the page address to be released.
* @param npages the number of page shall be released.
*
* @note this function is used for RT-Thread Application Module
*/
void rt_free_page(void *page_ptr, rt_size_t npages)
{
rt_page_free(page_ptr, npages);
/* update memory usage */
#ifdef RT_MEM_STATS
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
used_mem -= npages * RT_MM_PAGE_SIZE;
rt_sem_release(&heap_sem);
#endif
}
/**
* This function will allocate a block from system heap memory.
* - If the nbytes is less than zero,