/*
 * Memory allocation support for MP3, AAC and JPEG codes.
 *
 * We prepare static momory pool (mem_pool) and allocate
 * requested amount of memory linearly from this pool.
 * It is user's task responsibility to call pool_init()
 * when it starts using memory pool.
 */
#include <t_services.h>
#include "mempool.h"

static char mem_pool[POOL_SIZE];

static char *pool_ptr;

void pool_init()
{
    pool_ptr = mem_pool;
}

void pool_stat()
{
    cons_printf("pool: %d used\n", pool_ptr - mem_pool);
}

char *jsp_malloc(int size)
{
    char *mp;

    mp = pool_ptr;
    pool_ptr += size;
#ifdef XDEBUG
syslog(LOG_NOTICE, "mp = %x (%d) --> %d", mp, size, pool_ptr - mem_pool);
dly_tsk(10);
#endif
    if (pool_ptr - mem_pool > POOL_SIZE) {
        syslog(LOG_NOTICE, "alloc: %d used!!\n", pool_ptr - mem_pool);
        dly_tsk(10);
        return NULL;
    }
    return mp;
}

void jsp_free(char *mp)
{
    /* DO NOTHING */
}
