summaryrefslogtreecommitdiffstats
path: root/apps/playlist.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-30 14:01:33 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-30 14:01:33 +0000
commitd0b72e25903574acb1cf9184a6052cdd646dbc37 (patch)
tree5be8db5ee00b2a727e4821cf51a5f7bcf3991073 /apps/playlist.c
parentc940811ade7d99a0e0d414df7c6509672413684a (diff)
downloadrockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.tar.gz
rockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.tar.bz2
rockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.zip
GSoC/Buflib: Add buflib memory alocator to the core.
The buflib memory allocator is handle based and can free and compact, move or resize memory on demand. This allows to effeciently allocate memory dynamically without an MMU, by avoiding fragmentation through memory compaction. This patch adds the buflib library to the core, along with convinience wrappers to omit the context parameter. Compaction is not yet enabled, but will be in a later patch. Therefore, this acts as a replacement for buffer_alloc/buffer_get_buffer() with the benifit of a debug menu. See buflib.h for some API documentation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30380 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playlist.c')
-rw-r--r--apps/playlist.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 3d3b5f44f8..77d8141af8 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -84,7 +84,7 @@
#include "status.h"
#include "applimits.h"
#include "screens.h"
-#include "buffer.h"
+#include "core_alloc.h"
#include "misc.h"
#include "filefuncs.h"
#include "button.h"
@@ -1929,6 +1929,7 @@ static int rotate_index(const struct playlist_info* playlist, int index)
*/
void playlist_init(void)
{
+ int handle;
struct playlist_info* playlist = &current_playlist;
mutex_init(&current_playlist_mutex);
@@ -1940,18 +1941,19 @@ void playlist_init(void)
playlist->fd = -1;
playlist->control_fd = -1;
playlist->max_playlist_size = global_settings.max_files_in_playlist;
- playlist->indices = buffer_alloc(
- playlist->max_playlist_size * sizeof(int));
+ handle = core_alloc("playlist idx", playlist->max_playlist_size * sizeof(int));
+ playlist->indices = core_get_data(handle);
playlist->buffer_size =
AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir;
- playlist->buffer = buffer_alloc(playlist->buffer_size);
+ handle = core_alloc("playlist buf", playlist->buffer_size);
+ playlist->buffer = core_get_data(handle);
playlist->control_mutex = &current_playlist_mutex;
empty_playlist(playlist, true);
#ifdef HAVE_DIRCACHE
- playlist->filenames = buffer_alloc(
- playlist->max_playlist_size * sizeof(int));
+ handle = core_alloc("playlist dc", playlist->max_playlist_size * sizeof(int));
+ playlist->filenames = core_get_data(handle);
memset(playlist->filenames, 0xff,
playlist->max_playlist_size * sizeof(int));
create_thread(playlist_thread, playlist_stack, sizeof(playlist_stack),
@@ -3356,7 +3358,6 @@ int playlist_save(struct playlist_info* playlist, char *filename)
char tmp_buf[MAX_PATH+1];
int result = 0;
bool overwrite_current = false;
- int* index_buf = NULL;
char* old_buffer = NULL;
size_t old_buffer_size = 0;
@@ -3391,10 +3392,6 @@ int playlist_save(struct playlist_info* playlist, char *filename)
}
}
- /* in_ram buffer is unused for m3u files so we'll use for storing
- updated indices */
- index_buf = (int*)playlist->buffer;
-
/* use temporary pathname */
snprintf(path, sizeof(path), "%s_temp", playlist->filename);
overwrite_current = true;
@@ -3453,7 +3450,7 @@ int playlist_save(struct playlist_info* playlist, char *filename)
}
if (overwrite_current)
- index_buf[count] = lseek(fd, 0, SEEK_CUR);
+ playlist->seek_buf[count] = lseek(fd, 0, SEEK_CUR);
if (fdprintf(fd, "%s\n", tmp_buf) < 0)
{
@@ -3498,7 +3495,7 @@ int playlist_save(struct playlist_info* playlist, char *filename)
{
if (!(playlist->indices[index] & PLAYLIST_QUEUE_MASK))
{
- playlist->indices[index] = index_buf[count];
+ playlist->indices[index] = playlist->seek_buf[count];
count++;
}
index = (index+1)%playlist->amount;