summaryrefslogtreecommitdiff
path: root/firmware/core_alloc.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-04-03 10:48:14 +0100
committerAidan MacDonald <amachronic@protonmail.com>2022-09-19 15:09:51 -0400
commitf47aa584a8b447d8225fc5b09afb2d1fe6764c1d (patch)
tree8d767aa62d2415e555f49b3217f876afed39c310 /firmware/core_alloc.c
parentecfec3e9bf9178299cb0fe64bd530a81e10b1142 (diff)
downloadrockbox-f47aa584a8b447d8225fc5b09afb2d1fe6764c1d.tar.gz
rockbox-f47aa584a8b447d8225fc5b09afb2d1fe6764c1d.zip
buflib: add pin/unpin operation
An allocation is pinned by calling buflib_pin() to up its pin count. The pin count is like a reference count: when above 0, buflib won't move the allocation and won't call its move callbacks. This makes it safe to hold the pointer returned by buflib_get_data() across yields or allocations. Note that pinned allocations can still shrink because there are some use cases where this would be valid, if buffer users coordinate with the shrink callback. Change-Id: I0d0c2a8ac7d891d3ad6b3d0eb80c5b5a1b4b9a9d
Diffstat (limited to 'firmware/core_alloc.c')
-rw-r--r--firmware/core_alloc.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/firmware/core_alloc.c b/firmware/core_alloc.c
index bf2f8e8298..0374c801c1 100644
--- a/firmware/core_alloc.c
+++ b/firmware/core_alloc.c
@@ -104,6 +104,21 @@ bool core_shrink(int handle, void* new_start, size_t new_size)
104 return buflib_shrink(&core_ctx, handle, new_start, new_size); 104 return buflib_shrink(&core_ctx, handle, new_start, new_size);
105} 105}
106 106
107void core_pin(int handle)
108{
109 buflib_pin(&core_ctx, handle);
110}
111
112void core_unpin(int handle)
113{
114 buflib_unpin(&core_ctx, handle);
115}
116
117unsigned core_pin_count(int handle)
118{
119 return buflib_pin_count(&core_ctx, handle);
120}
121
107const char* core_get_name(int handle) 122const char* core_get_name(int handle)
108{ 123{
109 const char *name = buflib_get_name(&core_ctx, handle); 124 const char *name = buflib_get_name(&core_ctx, handle);