summaryrefslogtreecommitdiffstats
path: root/firmware/core_alloc.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 /firmware/core_alloc.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 'firmware/core_alloc.c')
-rw-r--r--firmware/core_alloc.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/firmware/core_alloc.c b/firmware/core_alloc.c
new file mode 100644
index 0000000000..75dfc75b86
--- /dev/null
+++ b/firmware/core_alloc.c
@@ -0,0 +1,57 @@
+
+#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);
+}