baa070cca6
This enables the ability to allocate (and free) memory dynamically without fragmentation, through compaction. This means allocations can move and fragmentation be reduced. Most changes are preparing Rockbox for this, which many times means adding a move callback which can temporarily disable movement when the corresponding code is in a critical section. For now, the audio buffer allocation has a central role, because it's the one having allocated most. This buffer is able to shrink itself, for which it needs to stop playback for a very short moment. For this, audio_buffer_available() returns the size of the audio buffer which can possibly be used by other allocations because the audio buffer can shrink. lastfm scrobbling and timestretch can now be toggled at runtime without requiring a reboot. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30381 a1c6a512-1295-4272-9138-f99709370657
56 lines
1.2 KiB
C
56 lines
1.2 KiB
C
|
|
#include <string.h>
|
|
#include "core_alloc.h"
|
|
#include "buflib.h"
|
|
#include "buffer.h"
|
|
|
|
/* not static so it can be discovered by core_get_data() */
|
|
struct buflib_context core_ctx;
|
|
void core_allocator_init(void)
|
|
{
|
|
buffer_init();
|
|
size_t size;
|
|
void *start = buffer_get_buffer(&size);
|
|
buflib_init(&core_ctx, start, size);
|
|
buffer_release_buffer(size);
|
|
}
|
|
|
|
int core_alloc(const char* name, size_t size)
|
|
{
|
|
return buflib_alloc_ex(&core_ctx, size, name, NULL);
|
|
}
|
|
|
|
int core_alloc_ex(const char* name, size_t size, struct buflib_callbacks *ops)
|
|
{
|
|
return buflib_alloc_ex(&core_ctx, size, name, ops);
|
|
}
|
|
|
|
size_t core_available(void)
|
|
{
|
|
return buflib_available(&core_ctx);
|
|
}
|
|
|
|
int core_free(int handle)
|
|
{
|
|
return buflib_free(&core_ctx, handle);
|
|
}
|
|
|
|
int core_alloc_maximum(const char* name, size_t *size, struct buflib_callbacks *ops)
|
|
{
|
|
return buflib_alloc_maximum(&core_ctx, name, size, ops);
|
|
}
|
|
|
|
bool core_shrink(int handle, void* new_start, size_t new_size)
|
|
{
|
|
return buflib_shrink(&core_ctx, handle, new_start, new_size);
|
|
}
|
|
|
|
int core_get_num_blocks(void)
|
|
{
|
|
return buflib_get_num_blocks(&core_ctx);
|
|
}
|
|
|
|
void core_print_block_at(int block_num, char* buf, size_t bufsize)
|
|
{
|
|
buflib_print_block_at(&core_ctx, block_num, buf, bufsize);
|
|
}
|