diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2013-08-22 12:12:47 +0200 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2013-08-26 09:42:47 +0200 |
commit | a2a2e14e0d400e1c82b4d02c4399602488578dc6 (patch) | |
tree | 87e63279ef95ce06315b492d85a009b58f3782b2 /lib/tlsf/src/tlsf.c | |
parent | b2e80edd1671833dc80eb0c5334cb6a2c58808e0 (diff) | |
download | rockbox-a2a2e14e0d400e1c82b4d02c4399602488578dc6.tar.gz rockbox-a2a2e14e0d400e1c82b4d02c4399602488578dc6.zip |
lua: Switch memory allocator from dl to tlsf
Instead of providing yet another memory allocator implementation
use tlsf and simply link tlsf library.
Another small improvement is to *grow* memory pool by grabbing
audiobuffer instead of just switching to use audiobuf exclusively.
Tested with simple lua 'memory eater' script.
This patch extends tlsf lib slightly. You can provide
void *get_new_area(size_t * size) function which will override
weak dummy implementation provided in lib itself. This allows to
automaticaly initialize memory pool as well as grow memory
pool if needed (for example grab audiobuffer when pluginbuffer
is exhaused).
Change-Id: I841af6b6b5bbbf546c14cbf139a7723fbb982f1b
Diffstat (limited to 'lib/tlsf/src/tlsf.c')
-rw-r--r-- | lib/tlsf/src/tlsf.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/tlsf/src/tlsf.c b/lib/tlsf/src/tlsf.c index 87f8d262ee..6866f0c9b0 100644 --- a/lib/tlsf/src/tlsf.c +++ b/lib/tlsf/src/tlsf.c | |||
@@ -395,6 +395,14 @@ static __inline__ bhdr_t *FIND_SUITABLE_BLOCK(tlsf_t * _tlsf, int *_fl, int *_sl | |||
395 | set_bit (_fl, &_tlsf -> fl_bitmap); \ | 395 | set_bit (_fl, &_tlsf -> fl_bitmap); \ |
396 | } while(0) | 396 | } while(0) |
397 | 397 | ||
398 | #if defined(ROCKBOX) | ||
399 | void * __attribute__((weak)) get_new_area(size_t * size) | ||
400 | { | ||
401 | (void)size; | ||
402 | return ((void *) ~0); | ||
403 | } | ||
404 | #endif | ||
405 | |||
398 | #if USE_SBRK || USE_MMAP | 406 | #if USE_SBRK || USE_MMAP |
399 | static __inline__ void *get_new_area(size_t * size) | 407 | static __inline__ void *get_new_area(size_t * size) |
400 | { | 408 | { |
@@ -615,7 +623,7 @@ void *tlsf_malloc(size_t size) | |||
615 | /******************************************************************/ | 623 | /******************************************************************/ |
616 | void *ret; | 624 | void *ret; |
617 | 625 | ||
618 | #if USE_MMAP || USE_SBRK | 626 | #if USE_MMAP || USE_SBRK || defined(ROCKBOX) |
619 | if (!mp) { | 627 | if (!mp) { |
620 | size_t area_size; | 628 | size_t area_size; |
621 | void *area; | 629 | void *area; |
@@ -657,7 +665,7 @@ void *tlsf_realloc(void *ptr, size_t size) | |||
657 | /******************************************************************/ | 665 | /******************************************************************/ |
658 | void *ret; | 666 | void *ret; |
659 | 667 | ||
660 | #if USE_MMAP || USE_SBRK | 668 | #if USE_MMAP || USE_SBRK || defined(ROCKBOX) |
661 | if (!mp) { | 669 | if (!mp) { |
662 | return tlsf_malloc(size); | 670 | return tlsf_malloc(size); |
663 | } | 671 | } |
@@ -705,7 +713,7 @@ void *malloc_ex(size_t size, void *mem_pool) | |||
705 | so they are not longer valid when the function fails */ | 713 | so they are not longer valid when the function fails */ |
706 | b = FIND_SUITABLE_BLOCK(tlsf, &fl, &sl); | 714 | b = FIND_SUITABLE_BLOCK(tlsf, &fl, &sl); |
707 | 715 | ||
708 | #if USE_MMAP || USE_SBRK | 716 | #if USE_MMAP || USE_SBRK || defined(ROCKBOX) |
709 | if (!b) { | 717 | if (!b) { |
710 | size_t area_size; | 718 | size_t area_size; |
711 | void *area; | 719 | void *area; |