From f47aa584a8b447d8225fc5b09afb2d1fe6764c1d Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sun, 3 Apr 2022 10:48:14 +0100 Subject: 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 --- firmware/include/core_alloc.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'firmware/include/core_alloc.h') diff --git a/firmware/include/core_alloc.h b/firmware/include/core_alloc.h index f535fc1f6e..87246bcbd6 100644 --- a/firmware/include/core_alloc.h +++ b/firmware/include/core_alloc.h @@ -14,6 +14,9 @@ int core_alloc(const char* name, size_t size); int core_alloc_ex(const char* name, size_t size, struct buflib_callbacks *ops); int core_alloc_maximum(const char* name, size_t *size, struct buflib_callbacks *ops); bool core_shrink(int handle, void* new_start, size_t new_size); +void core_pin(int handle); +void core_unpin(int handle); +unsigned core_pin_count(int handle); int core_free(int handle); size_t core_available(void); size_t core_allocatable(void); -- cgit v1.2.3