summaryrefslogtreecommitdiffstats
path: root/apps/codecs/libtremor/oggmalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libtremor/oggmalloc.c')
-rw-r--r--apps/codecs/libtremor/oggmalloc.c80
1 files changed, 29 insertions, 51 deletions
diff --git a/apps/codecs/libtremor/oggmalloc.c b/apps/codecs/libtremor/oggmalloc.c
index 6da7cfcedc..3d60370641 100644
--- a/apps/codecs/libtremor/oggmalloc.c
+++ b/apps/codecs/libtremor/oggmalloc.c
@@ -1,85 +1,63 @@
#include "os_types.h"
+#include "../lib/tlsf/src/tlsf.h"
-#if defined(CPU_ARM) || defined(CPU_COLDFIRE)
+#if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS)
#include <setjmp.h>
extern jmp_buf rb_jump_buf;
+#define LONGJMP(x) longjmp(rb_jump_buf, x)
+#elif defined(SIMULATOR)
+#define LONGJMP(x) do { DEBUGF("Vorbis: allocation failed!\n"); return NULL; } while (false)
+#else
+#define LONGJMP(x) return NULL
#endif
-static size_t tmp_ptr;
-
void ogg_malloc_init(void)
{
- mallocbuf = ci->codec_get_buffer(&bufsize);
- tmp_ptr = bufsize & ~3;
- mem_ptr = 0;
+ size_t bufsize;
+ void* buf = ci->codec_get_buffer(&bufsize);
+ init_memory_pool(bufsize, buf);
}
-void *ogg_malloc(size_t size)
+void ogg_malloc_destroy()
{
- void* x;
-
- size = (size + 3) & ~3;
-
- if (mem_ptr + size > tmp_ptr)
-#if defined(CPU_ARM) || defined(CPU_COLDFIRE)
- longjmp(rb_jump_buf, 1);
-#else
- return NULL;
-#endif
-
- x = &mallocbuf[mem_ptr];
- mem_ptr += size; /* Keep memory 32-bit aligned */
-
- return x;
+ size_t bufsize;
+ void* buf = ci->codec_get_buffer(&bufsize);
+ destroy_memory_pool(buf);
}
-void *ogg_tmpmalloc(size_t size)
+void *ogg_malloc(size_t size)
{
- size = (size + 3) & ~3;
+ void* x = tlsf_malloc(size);
- if (mem_ptr + size > tmp_ptr)
- return NULL;
+ if (x == NULL)
+ LONGJMP(1);
- tmp_ptr -= size;
- return &mallocbuf[tmp_ptr];
+ return x;
}
void *ogg_calloc(size_t nmemb, size_t size)
{
- void *x;
- x = ogg_malloc(nmemb * size);
- if (x == NULL)
- return NULL;
- ci->memset(x, 0, nmemb * size);
- return x;
-}
+ void *x = tlsf_calloc(nmemb, size);
-void *ogg_tmpcalloc(size_t nmemb, size_t size)
-{
- void *x;
- x = ogg_tmpmalloc(nmemb * size);
if (x == NULL)
- return NULL;
- ci->memset(x, 0, nmemb * size);
+ LONGJMP(1);
+
return x;
}
void *ogg_realloc(void *ptr, size_t size)
{
- void *x;
- (void)ptr;
- x = ogg_malloc(size);
- return x;
-}
+ void *x = tlsf_realloc(ptr, size);
-long ogg_tmpmalloc_pos(void)
-{
- return tmp_ptr;
+ if (x == NULL)
+ LONGJMP(1);
+
+ return x;
}
-void ogg_tmpmalloc_free(long pos)
+void ogg_free(void* ptr)
{
- tmp_ptr = pos;
+ tlsf_free(ptr);
}
/* Allocate IRAM buffer */