lcd-m6sp.c: remove \r
[kugel-rb.git] / apps / codecs / libtremor / oggmalloc.c
blob3d60370641665a59629147c026a2ab74091c44f8
1 #include "os_types.h"
2 #include "../lib/tlsf/src/tlsf.h"
4 #if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS)
5 #include <setjmp.h>
6 extern jmp_buf rb_jump_buf;
7 #define LONGJMP(x) longjmp(rb_jump_buf, x)
8 #elif defined(SIMULATOR)
9 #define LONGJMP(x) do { DEBUGF("Vorbis: allocation failed!\n"); return NULL; } while (false)
10 #else
11 #define LONGJMP(x) return NULL
12 #endif
14 void ogg_malloc_init(void)
16 size_t bufsize;
17 void* buf = ci->codec_get_buffer(&bufsize);
18 init_memory_pool(bufsize, buf);
21 void ogg_malloc_destroy()
23 size_t bufsize;
24 void* buf = ci->codec_get_buffer(&bufsize);
25 destroy_memory_pool(buf);
28 void *ogg_malloc(size_t size)
30 void* x = tlsf_malloc(size);
32 if (x == NULL)
33 LONGJMP(1);
35 return x;
38 void *ogg_calloc(size_t nmemb, size_t size)
40 void *x = tlsf_calloc(nmemb, size);
42 if (x == NULL)
43 LONGJMP(1);
45 return x;
48 void *ogg_realloc(void *ptr, size_t size)
50 void *x = tlsf_realloc(ptr, size);
52 if (x == NULL)
53 LONGJMP(1);
55 return x;
58 void ogg_free(void* ptr)
60 tlsf_free(ptr);
63 /* Allocate IRAM buffer */
64 static unsigned char iram_buff[IRAM_IBSS_SIZE] IBSS_ATTR __attribute__ ((aligned (16)));
65 static size_t iram_remain;
67 void iram_malloc_init(void){
68 iram_remain=IRAM_IBSS_SIZE;
71 void *iram_malloc(size_t size){
72 void* x;
74 /* always ensure 16-byte aligned */
75 if(size&0x0f)
76 size=(size-(size&0x0f))+16;
78 if(size>iram_remain)
79 return NULL;
81 x = &iram_buff[IRAM_IBSS_SIZE-iram_remain];
82 iram_remain-=size;
84 return x;