summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rockmalloc.c
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2013-08-22 12:12:47 +0200
committerMarcin Bukat <marcin.bukat@gmail.com>2013-08-26 09:42:47 +0200
commita2a2e14e0d400e1c82b4d02c4399602488578dc6 (patch)
tree87e63279ef95ce06315b492d85a009b58f3782b2 /apps/plugins/lua/rockmalloc.c
parentb2e80edd1671833dc80eb0c5334cb6a2c58808e0 (diff)
downloadrockbox-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 'apps/plugins/lua/rockmalloc.c')
-rw-r--r--apps/plugins/lua/rockmalloc.c63
1 files changed, 0 insertions, 63 deletions
diff --git a/apps/plugins/lua/rockmalloc.c b/apps/plugins/lua/rockmalloc.c
deleted file mode 100644
index 14a43396ea..0000000000
--- a/apps/plugins/lua/rockmalloc.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 Dan Everton (safetydan)
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "plugin.h"
23#include "rockmalloc.h"
24#include "malloc.c"
25
26void *rocklua_morecore(int size)
27{
28 static char *sbrk_top = NULL;
29 static ssize_t total_size = 0;
30 void *ptr = 0;
31
32 if (size > 0) {
33 size = size + 4 - (size % 4);
34
35 if (sbrk_top == NULL) {
36 sbrk_top = rb->plugin_get_buffer((size_t *) &total_size);
37 }
38
39 if (sbrk_top == NULL || size + 4 > abs(total_size)) {
40 /* Try the audio buffer */
41 sbrk_top = rb->plugin_get_audio_buffer((size_t *) &total_size);
42
43 if(sbrk_top == NULL || size + 4 > abs(total_size)) {
44 printf("malloc failed for %d!\n", size);
45 return (void *) MFAIL;
46 }
47 }
48
49 ptr = sbrk_top + 4;
50 *((unsigned int *) sbrk_top) = size;
51
52 sbrk_top += size + 4;
53 total_size -= size + 4;
54
55 return ptr;
56 } else if (size < 0) {
57 /* we don't currently support shrink behavior */
58 return (void *) MFAIL;
59 } else {
60 return sbrk_top;
61 }
62}
63