diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-04-03 11:16:39 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-10-16 14:50:39 +0100 |
commit | 1718cf5f8a39b922eba3ad1b3c9a9570188362b1 (patch) | |
tree | 4f6bf81cb4f382ca04856b98492289825133c5ae /firmware/font.c | |
parent | b16bae6fe624d30631bf83290e204197ab136c12 (diff) | |
download | rockbox-1718cf5f8a39b922eba3ad1b3c9a9570188362b1.tar.gz rockbox-1718cf5f8a39b922eba3ad1b3c9a9570188362b1.zip |
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
Diffstat (limited to 'firmware/font.c')
-rw-r--r-- | firmware/font.c | 16 |
1 files changed, 6 insertions, 10 deletions
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; | |||
90 | 90 | ||
91 | struct buflib_alloc_data { | 91 | struct buflib_alloc_data { |
92 | struct font font; /* must be the first member! */ | 92 | struct font font; /* must be the first member! */ |
93 | int handle_locks; /* is the buflib handle currently locked? */ | ||
94 | int refcount; /* how many times has this font been loaded? */ | 93 | int refcount; /* how many times has this font been loaded? */ |
95 | unsigned char buffer[]; | 94 | unsigned char buffer[]; |
96 | }; | 95 | }; |
@@ -107,9 +106,6 @@ static int buflibmove_callback(int handle, void* current, void* new) | |||
107 | struct buflib_alloc_data *alloc = (struct buflib_alloc_data*)current; | 106 | struct buflib_alloc_data *alloc = (struct buflib_alloc_data*)current; |
108 | ptrdiff_t diff = new - current; | 107 | ptrdiff_t diff = new - current; |
109 | 108 | ||
110 | if (alloc->handle_locks > 0) | ||
111 | return BUFLIB_CB_CANNOT_MOVE; | ||
112 | |||
113 | #define UPDATE(x) if (x) { x = PTR_ADD(x, diff); } | 109 | #define UPDATE(x) if (x) { x = PTR_ADD(x, diff); } |
114 | 110 | ||
115 | UPDATE(alloc->font.bits); | 111 | UPDATE(alloc->font.bits); |
@@ -129,18 +125,18 @@ static void lock_font_handle(int handle, bool lock) | |||
129 | { | 125 | { |
130 | if ( handle < 0 ) | 126 | if ( handle < 0 ) |
131 | return; | 127 | return; |
132 | struct buflib_alloc_data *alloc = core_get_data(handle); | 128 | |
133 | if ( lock ) | 129 | if (lock) |
134 | alloc->handle_locks++; | 130 | core_pin(handle); |
135 | else | 131 | else |
136 | alloc->handle_locks--; | 132 | core_unpin(handle); |
137 | } | 133 | } |
138 | 134 | ||
139 | void font_lock(int font_id, bool lock) | 135 | void font_lock(int font_id, bool lock) |
140 | { | 136 | { |
141 | if( font_id < 0 || font_id >= MAXFONTS ) | 137 | if( font_id < 0 || font_id >= MAXFONTS ) |
142 | return; | 138 | return; |
143 | if( buflib_allocations[font_id] >= 0 ) | 139 | if( buflib_allocations[font_id] > 0 ) |
144 | lock_font_handle(buflib_allocations[font_id], lock); | 140 | lock_font_handle(buflib_allocations[font_id], lock); |
145 | } | 141 | } |
146 | 142 | ||
@@ -522,8 +518,8 @@ int font_load_ex( const char *path, size_t buf_size, int glyphs ) | |||
522 | return -1; | 518 | return -1; |
523 | } | 519 | } |
524 | struct buflib_alloc_data *pdata; | 520 | struct buflib_alloc_data *pdata; |
521 | core_pin(handle); | ||
525 | pdata = core_get_data(handle); | 522 | pdata = core_get_data(handle); |
526 | pdata->handle_locks = 1; | ||
527 | pdata->refcount = 1; | 523 | pdata->refcount = 1; |
528 | 524 | ||
529 | /* load and init */ | 525 | /* load and init */ |