summaryrefslogtreecommitdiff
path: root/apps/tagcache.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/tagcache.c
parentc940811ade7d99a0e0d414df7c6509672413684a (diff)
downloadrockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.zip
rockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.tar.gz
rockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.tar.bz2
rockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.tar.xz
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/tagcache.c')
-rw-r--r--apps/tagcache.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 52e059a..753675f 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -74,7 +74,7 @@
#include "usb.h"
#include "metadata.h"
#include "tagcache.h"
-#include "buffer.h"
+#include "core_alloc.h"
#include "crc32.h"
#include "misc.h"
#include "settings.h"
@@ -3082,6 +3082,7 @@ static bool commit(void)
return true;
}
+static int tempbuf_handle;
static void allocate_tempbuf(void)
{
/* Yeah, malloc would be really nice now :) */
@@ -3089,7 +3090,8 @@ static void allocate_tempbuf(void)
tempbuf_size = 32*1024*1024;
tempbuf = malloc(tempbuf_size);
#else
- tempbuf = buffer_get_buffer(&tempbuf_size);
+ tempbuf_handle = core_alloc_maximum("tc tempbuf", &tempbuf_size, NULL);
+ tempbuf = core_get_data(tempbuf_handle);
#endif
}
@@ -3101,7 +3103,7 @@ static void free_tempbuf(void)
#ifdef __PCTOOL__
free(tempbuf);
#else
- buffer_release_buffer(0);
+ tempbuf_handle = core_free(tempbuf_handle);
#endif
tempbuf = NULL;
tempbuf_size = 0;
@@ -3829,9 +3831,10 @@ static bool allocate_tagcache(void)
* Now calculate the required cache size plus
* some extra space for alignment fixes.
*/
- tc_stat.ramcache_allocated = tcmh.tch.datasize + 128 + TAGCACHE_RESERVE +
+ tc_stat.ramcache_allocated = tcmh.tch.datasize + 256 + TAGCACHE_RESERVE +
sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *);
- ramcache_hdr = buffer_alloc(tc_stat.ramcache_allocated + 128);
+ int handle = core_alloc("tc ramcache", tc_stat.ramcache_allocated);
+ ramcache_hdr = core_get_data(handle);
memset(ramcache_hdr, 0, sizeof(struct ramcache_header));
memcpy(&current_tcmh, &tcmh, sizeof current_tcmh);
logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated);
@@ -3845,7 +3848,7 @@ static bool tagcache_dumpload(void)
struct statefile_header shdr;
int fd, rc;
long offpos;
- int i;
+ int i, handle;
fd = open(TAGCACHE_STATEFILE, O_RDONLY);
if (fd < 0)
@@ -3855,7 +3858,6 @@ static bool tagcache_dumpload(void)
}
/* Check the statefile memory placement */
- ramcache_hdr = buffer_alloc(0);
rc = read(fd, &shdr, sizeof(struct statefile_header));
if (rc != sizeof(struct statefile_header)
|| shdr.magic != TAGCACHE_STATEFILE_MAGIC
@@ -3867,13 +3869,14 @@ static bool tagcache_dumpload(void)
return false;
}
- offpos = (long)ramcache_hdr - (long)shdr.hdr;
/* Lets allocate real memory and load it */
- ramcache_hdr = buffer_alloc(shdr.tc_stat.ramcache_allocated);
+ handle = core_alloc("tc ramcache", shdr.tc_stat.ramcache_allocated);
+ ramcache_hdr = core_get_data(handle);
rc = read(fd, ramcache_hdr, shdr.tc_stat.ramcache_allocated);
close(fd);
+ offpos = (long)ramcache_hdr - (long)shdr.hdr;
if (rc != shdr.tc_stat.ramcache_allocated)
{
logf("read failure!");