forked from len0rd/rockbox
GSoC/Buflib: Enable compaction in buflib.
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
This commit is contained in:
parent
d0b72e2590
commit
baa070cca6
28 changed files with 865 additions and 298 deletions
|
@ -184,6 +184,26 @@ static unsigned char highest_attr = 0;
|
|||
static int viewer_count = 0;
|
||||
|
||||
static int strdup_handle, strdup_bufsize, strdup_cur_idx;
|
||||
static int move_callback(int handle, void* current, void* new)
|
||||
{
|
||||
/*could compare to strdup_handle, but ops is only used once */
|
||||
(void)handle;
|
||||
size_t diff = new - current;
|
||||
#define FIX_PTR(x) \
|
||||
{ if ((void*)x > current && (void*)x < (current+strdup_bufsize)) x+= diff; }
|
||||
for(int i = 0; i < filetype_count; i++)
|
||||
{
|
||||
FIX_PTR(filetypes[i].extension);
|
||||
FIX_PTR(filetypes[i].plugin);
|
||||
}
|
||||
return BUFLIB_CB_OK;
|
||||
}
|
||||
|
||||
static struct buflib_callbacks ops = {
|
||||
.move_callback = move_callback,
|
||||
.shrink_callback = NULL,
|
||||
};
|
||||
|
||||
static char *filetypes_strdup(char* string)
|
||||
{
|
||||
char *buffer = core_get_data(strdup_handle) + strdup_cur_idx;
|
||||
|
@ -323,7 +343,7 @@ void filetype_init(void)
|
|||
return;
|
||||
|
||||
strdup_bufsize = filesize(fd);
|
||||
strdup_handle = core_alloc("filetypes", strdup_bufsize);
|
||||
strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops);
|
||||
if (strdup_handle <= 0)
|
||||
return;
|
||||
read_builtin_types();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue