summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/tlsf_helper.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/tlsf_helper.c
parentb2e80edd1671833dc80eb0c5334cb6a2c58808e0 (diff)
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/tlsf_helper.c')
-rw-r--r--apps/plugins/lua/tlsf_helper.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/apps/plugins/lua/tlsf_helper.c b/apps/plugins/lua/tlsf_helper.c
new file mode 100644
index 0000000000..edf32eecf9
--- /dev/null
+++ b/apps/plugins/lua/tlsf_helper.c
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2013 Marcin Bukat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "plugin.h"
+#include <tlsf.h>
+
+void *get_new_area(size_t *size)
+{
+ static char *pluginbuf_ptr = NULL;
+ static char *audiobuf_ptr = NULL;
+
+ if (pluginbuf_ptr == NULL)
+ {
+ pluginbuf_ptr = rb->plugin_get_buffer(size);
+
+ /* kill tlsf signature if any */
+ memset(pluginbuf_ptr, 0, 4);
+
+ return pluginbuf_ptr;
+ }
+
+ if (audiobuf_ptr == NULL)
+ {
+ /* grab audiobuffer */
+ audiobuf_ptr = rb->plugin_get_audio_buffer(size);
+
+ return audiobuf_ptr;
+ }
+
+ return ((void *) ~0);
+}