diff options
| author | [email protected] <[email protected]> | 2011-07-04 23:48:07 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2011-07-04 23:48:07 +0000 |
| commit | cea21370a40d8b9ace858c477d5cedf214cdf520 (patch) | |
| tree | 8144ca112fbc77be725326182d0dcb3d530c55f3 /src/slab.c | |
| parent | 3bc0dd4a825f80a0e56d8a92e633a06435f1ac40 (diff) | |
rewrite module memory allocator
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1618 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'src/slab.c')
| -rw-r--r-- | src/slab.c | 59 |
1 files changed, 13 insertions, 46 deletions
diff --git a/src/slab.c b/src/slab.c index af044662af..378faea1d8 100644 --- a/src/slab.c +++ b/src/slab.c @@ -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, |
