summaryrefslogtreecommitdiffstats
path: root/firmware/include
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-05-29 07:07:34 +0200
committerThomas Martitz <kugel@rockbox.org>2013-07-07 10:46:07 +0200
commitaf4e408555659f42db5b8c9a1d6a68143b2328da (patch)
treefaa15141187583097b8e6d2451f7a0f25ce5a33b /firmware/include
parentf9e47c6886a6fb69e8d25b07d256dd82e4904839 (diff)
downloadrockbox-af4e408555659f42db5b8c9a1d6a68143b2328da.tar.gz
rockbox-af4e408555659f42db5b8c9a1d6a68143b2328da.tar.bz2
rockbox-af4e408555659f42db5b8c9a1d6a68143b2328da.zip
buflib: Change buflib_available() and add buflib_allocatable().
buflib_allocatable() is what buflib_available() was before (it was in fact simply renamed). It returns the largest contiguous block of memory. This can be allocated and will definitely succeed, although larger allocations may also succeed if the buffer can be compacted and shrinked. buflib_available() now counts all free bytes, contiguous or not. This better matches the description and how the caller use it. Change-Id: I511e4eb5f4cf1821d957b3f4ef8a685ce40fe289 Reviewed-on: http://gerrit.rockbox.org/481 Reviewed-by: Thomas Martitz <kugel@rockbox.org> Tested-by: Thomas Martitz <kugel@rockbox.org>
Diffstat (limited to 'firmware/include')
-rw-r--r--firmware/include/buflib.h15
-rw-r--r--firmware/include/core_alloc.h1
2 files changed, 11 insertions, 5 deletions
diff --git a/firmware/include/buflib.h b/firmware/include/buflib.h
index 6c9ccf7402..7183951c6c 100644
--- a/firmware/include/buflib.h
+++ b/firmware/include/buflib.h
@@ -143,15 +143,20 @@ void buflib_init(struct buflib_context *context, void *buf, size_t size);
/**
- * Returns how many bytes left the buflib has to satisfy allocations.
+ * Returns the amount of unallocated bytes. It does not mean this amount
+ * can be actually allocated because they might not be contiguous.
*
- * This function does not yet consider possible compaction so there might
- * be more space left. This may change in the future.
- *
- * Returns: The number of bytes left in the memory pool.
+ * Returns: The number of unallocated bytes in the memory pool.
*/
size_t buflib_available(struct buflib_context *ctx);
+/**
+ * Returns the biggest possible allocation that can be determined to succeed.
+ *
+ * Returns: The amount of bytes of the biggest unallocated, contiguous region.
+ */
+size_t buflib_allocatable(struct buflib_context *ctx);
+
/**
* Allocates memory from buflib's memory pool
diff --git a/firmware/include/core_alloc.h b/firmware/include/core_alloc.h
index d234947db1..a100b7cc6c 100644
--- a/firmware/include/core_alloc.h
+++ b/firmware/include/core_alloc.h
@@ -16,6 +16,7 @@ int core_alloc_maximum(const char* name, size_t *size, struct buflib_callbacks *
bool core_shrink(int handle, void* new_start, size_t new_size);
int core_free(int handle);
size_t core_available(void);
+size_t core_allocatable(void);
/* DO NOT ADD wrappers for buflib_buffer_out/in. They do not call
* the move callbacks and are therefore unsafe in the core */