diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-08-30 14:01:45 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-08-30 14:01:45 +0000 |
commit | baa070cca6d459a7c5aed81f29e4cc4f6c7410b3 (patch) | |
tree | 5123360aea420b96e4a97a8e88cf51b4277152d9 /apps/filetypes.c | |
parent | d0b72e25903574acb1cf9184a6052cdd646dbc37 (diff) | |
download | rockbox-baa070cca6d459a7c5aed81f29e4cc4f6c7410b3.tar.gz rockbox-baa070cca6d459a7c5aed81f29e4cc4f6c7410b3.zip |
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
Diffstat (limited to 'apps/filetypes.c')
-rw-r--r-- | apps/filetypes.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c index c52c734a1d..942ff329fe 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c | |||
@@ -184,6 +184,26 @@ static unsigned char highest_attr = 0; | |||
184 | static int viewer_count = 0; | 184 | static int viewer_count = 0; |
185 | 185 | ||
186 | static int strdup_handle, strdup_bufsize, strdup_cur_idx; | 186 | static int strdup_handle, strdup_bufsize, strdup_cur_idx; |
187 | static int move_callback(int handle, void* current, void* new) | ||
188 | { | ||
189 | /*could compare to strdup_handle, but ops is only used once */ | ||
190 | (void)handle; | ||
191 | size_t diff = new - current; | ||
192 | #define FIX_PTR(x) \ | ||
193 | { if ((void*)x > current && (void*)x < (current+strdup_bufsize)) x+= diff; } | ||
194 | for(int i = 0; i < filetype_count; i++) | ||
195 | { | ||
196 | FIX_PTR(filetypes[i].extension); | ||
197 | FIX_PTR(filetypes[i].plugin); | ||
198 | } | ||
199 | return BUFLIB_CB_OK; | ||
200 | } | ||
201 | |||
202 | static struct buflib_callbacks ops = { | ||
203 | .move_callback = move_callback, | ||
204 | .shrink_callback = NULL, | ||
205 | }; | ||
206 | |||
187 | static char *filetypes_strdup(char* string) | 207 | static char *filetypes_strdup(char* string) |
188 | { | 208 | { |
189 | char *buffer = core_get_data(strdup_handle) + strdup_cur_idx; | 209 | char *buffer = core_get_data(strdup_handle) + strdup_cur_idx; |
@@ -323,7 +343,7 @@ void filetype_init(void) | |||
323 | return; | 343 | return; |
324 | 344 | ||
325 | strdup_bufsize = filesize(fd); | 345 | strdup_bufsize = filesize(fd); |
326 | strdup_handle = core_alloc("filetypes", strdup_bufsize); | 346 | strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops); |
327 | if (strdup_handle <= 0) | 347 | if (strdup_handle <= 0) |
328 | return; | 348 | return; |
329 | read_builtin_types(); | 349 | read_builtin_types(); |