Get the plugins synced up with the threading changes.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14881 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2007-09-28 11:12:45 +00:00
parent a13a1d5492
commit d7cb90722f
5 changed files with 109 additions and 62 deletions

View file

@ -27,40 +27,71 @@
extern struct plugin_api* rb;
long mem_ptr;
long bufsize;
unsigned char* mallocbuf;
/* Main allocator */
static off_t mem_ptr;
static size_t bufsize;
static unsigned char* mallocbuf;
void mpeg2_alloc_init(unsigned char* buf, int mallocsize)
/* libmpeg2 allocator */
static off_t mpeg2_mem_ptr;
static size_t mpeg2_bufsize;
static unsigned char *mpeg2_mallocbuf;
static void * mpeg_malloc_internal (unsigned char *mallocbuf,
off_t *mem_ptr,
size_t bufsize,
unsigned size,
int reason)
{
mem_ptr = 0;
bufsize = mallocsize;
mallocbuf = buf;
rb->memset(buf,0,bufsize);
void *x;
return;
}
void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason)
{
void* x;
(void)reason;
DEBUGF("mpeg2_malloc(%d,%d)\n",size,reason);
if (mem_ptr + (long)size > bufsize) {
if (*mem_ptr + size > bufsize)
{
DEBUGF("OUT OF MEMORY\n");
return NULL;
}
x=&mallocbuf[mem_ptr];
mem_ptr+=(size+3)&~3; /* Keep memory 32-bit aligned */
x = &mallocbuf[*mem_ptr];
*mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */
return(x);
return x;
(void)reason;
}
void mpeg2_free(void* ptr) {
(void)ptr;
void *mpeg_malloc(size_t size, mpeg2_alloc_t reason)
{
return mpeg_malloc_internal(mallocbuf, &mem_ptr, bufsize, size,
reason);
}
size_t mpeg_alloc_init(unsigned char *buf, size_t mallocsize,
size_t libmpeg2size)
{
mem_ptr = 0;
bufsize = mallocsize;
/* Line-align buffer */
mallocbuf = (char *)(((intptr_t)buf + 15) & ~15);
/* Adjust for real size */
bufsize -= mallocbuf - buf;
rb->memset(buf,0,bufsize);
/* Separate allocator for video */
libmpeg2size = (libmpeg2size + 15) & ~15;
if (mpeg_malloc_internal(mallocbuf, &mem_ptr,
bufsize, libmpeg2size, 0) == NULL)
{
return 0;
}
mpeg2_mallocbuf = mallocbuf;
mpeg2_mem_ptr = 0;
mpeg2_bufsize = libmpeg2size;
#if NUM_CORES > 1
flush_icache();
#endif
return bufsize - mpeg2_bufsize;
}
/* gcc may want to use memcpy before rb is initialised, so here's a trivial
@ -77,18 +108,30 @@ void *memcpy(void *dest, const void *src, size_t n) {
return dest;
}
/* The following are expected by libmad */
void* codec_malloc(size_t size)
void * mpeg2_malloc(unsigned size, mpeg2_alloc_t reason)
{
return mpeg2_malloc(size,-3);
return mpeg_malloc_internal(mpeg2_mallocbuf, &mpeg2_mem_ptr,
mpeg2_bufsize, size, reason);
}
void* codec_calloc(size_t nmemb, size_t size)
void mpeg2_free(void *ptr)
{
(void)ptr;
}
/* The following are expected by libmad */
void * codec_malloc(size_t size)
{
return mpeg_malloc_internal(mallocbuf, &mem_ptr,
bufsize, size, -3);
}
void * codec_calloc(size_t nmemb, size_t size)
{
void* ptr;
ptr = mpeg2_malloc(nmemb*size,-3);
ptr = mpeg_malloc_internal(mallocbuf, &mem_ptr,
bufsize, nmemb*size, -3);
if (ptr)
rb->memset(ptr,0,size);
@ -96,7 +139,8 @@ void* codec_calloc(size_t nmemb, size_t size)
return ptr;
}
void codec_free(void* ptr) {
void codec_free(void* ptr)
{
(void)ptr;
}