From 1718cf5f8a39b922eba3ad1b3c9a9570188362b1 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sun, 3 Apr 2022 11:16:39 +0100 Subject: Convert a number of allocations to use buflib pinning Several places in the codebase implemented an ad-hoc form of pinning; they can be converted to use buflib pinning instead. Change-Id: I4450be007e80f6c9cc9f56c2929fa4b9b85ebff3 --- firmware/font.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'firmware/font.c') diff --git a/firmware/font.c b/firmware/font.c index 724cb84d57..7ce64ed47d 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -90,7 +90,6 @@ extern struct font sysfont; struct buflib_alloc_data { struct font font; /* must be the first member! */ - int handle_locks; /* is the buflib handle currently locked? */ int refcount; /* how many times has this font been loaded? */ unsigned char buffer[]; }; @@ -107,9 +106,6 @@ static int buflibmove_callback(int handle, void* current, void* new) struct buflib_alloc_data *alloc = (struct buflib_alloc_data*)current; ptrdiff_t diff = new - current; - if (alloc->handle_locks > 0) - return BUFLIB_CB_CANNOT_MOVE; - #define UPDATE(x) if (x) { x = PTR_ADD(x, diff); } UPDATE(alloc->font.bits); @@ -129,18 +125,18 @@ static void lock_font_handle(int handle, bool lock) { if ( handle < 0 ) return; - struct buflib_alloc_data *alloc = core_get_data(handle); - if ( lock ) - alloc->handle_locks++; + + if (lock) + core_pin(handle); else - alloc->handle_locks--; + core_unpin(handle); } void font_lock(int font_id, bool lock) { if( font_id < 0 || font_id >= MAXFONTS ) return; - if( buflib_allocations[font_id] >= 0 ) + if( buflib_allocations[font_id] > 0 ) lock_font_handle(buflib_allocations[font_id], lock); } @@ -522,8 +518,8 @@ int font_load_ex( const char *path, size_t buf_size, int glyphs ) return -1; } struct buflib_alloc_data *pdata; + core_pin(handle); pdata = core_get_data(handle); - pdata->handle_locks = 1; pdata->refcount = 1; /* load and init */ -- cgit v1.2.3