Add core_get_data_pinned(), use it where possible

Change-Id: I1b2f62f27780f99423085d2fffc972ea2701f998
This commit is contained in:
Aidan MacDonald 2023-01-14 18:50:15 +00:00
parent 9e53d5541f
commit 67cb2e3cdc
3 changed files with 19 additions and 6 deletions

View file

@ -80,11 +80,12 @@ int core_load_key_remap(const char *filename)
int handle = core_alloc(bufsize);
if (handle > 0)
{
core_pin(handle);
if (read(fd, core_get_data(handle), bufsize) == (ssize_t)bufsize)
void *data = core_get_data_pinned(handle);
if (read(fd, data, bufsize) == (ssize_t)bufsize)
count = action_set_keymap_handle(handle, count);
core_unpin(handle);
core_put_data_pinned(data);
}
close(fd);

View file

@ -1635,8 +1635,7 @@ int core_load_bmp(const char * filename, struct bitmap *bm, const int bmformat,
handle = core_alloc_ex(buf_size, ops);
if (handle > 0)
{
core_pin(handle);
bm->data = core_get_data(handle);
bm->data = core_get_data_pinned(handle);
lseek(fd, 0, SEEK_SET); /* reset to beginning of file */
size_read = read_bmp_fd(fd, bm, buf_size, bmformat, NULL);
@ -1645,9 +1644,10 @@ int core_load_bmp(const char * filename, struct bitmap *bm, const int bmformat,
core_shrink(handle, bm->data, size_read);
*buf_reqd = size_read;
}
core_put_data_pinned(bm->data);
bm->data = NULL; /* do this to force a crash later if the
caller doesnt call core_get_data() */
core_unpin(handle);
}
else
*buf_reqd = buf_size; /* couldn't allocate pass bytes needed */

View file

@ -45,6 +45,18 @@ static inline void* core_get_data(int handle)
return buflib_get_data(&core_ctx, handle);
}
static inline void* core_get_data_pinned(int handle)
{
extern struct buflib_context core_ctx;
return buflib_get_data_pinned(&core_ctx, handle);
}
static inline void core_put_data_pinned(void *data)
{
extern struct buflib_context core_ctx;
buflib_put_data_pinned(&core_ctx, data);
}
/* core context chunk_alloc */
static inline bool core_chunk_alloc_init(struct chunk_alloc_header *hdr,
size_t chunk_size, size_t max_chunks)