Remove buflib allocation names, part two
Remove allocation names from the buflib API and fix up all callers. Change-Id: I3df922e258d5f0d711d70e72b56b4ed634fb0f5a
This commit is contained in:
parent
3301c5aa6d
commit
1e9ad3ca0d
39 changed files with 69 additions and 115 deletions
|
@ -1202,7 +1202,7 @@ int action_set_keymap(struct button_mapping* core_keymap, int count)
|
|||
return action_set_keymap_handle(0, 0);
|
||||
|
||||
size_t keyremap_buf_size = count * sizeof(struct button_mapping);
|
||||
int handle = core_alloc("keyremap", keyremap_buf_size);
|
||||
int handle = core_alloc(keyremap_buf_size);
|
||||
if (handle < 0)
|
||||
return -6;
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ int core_load_key_remap(const char *filename)
|
|||
return -1;
|
||||
|
||||
size_t bufsize = count * sizeof(struct button_mapping);
|
||||
int handle = core_alloc("keyremap", bufsize);
|
||||
int handle = core_alloc(bufsize);
|
||||
if (handle > 0)
|
||||
{
|
||||
core_pin(handle);
|
||||
|
|
|
@ -515,7 +515,7 @@ static int bf_action_cb(int action, struct gui_synclist* list)
|
|||
else
|
||||
{
|
||||
splash(HZ/1, "Attempting a 64k allocation");
|
||||
int handle = core_alloc("test", 64<<10);
|
||||
int handle = core_alloc(64<<10);
|
||||
splash(HZ/2, (handle > 0) ? "Success":"Fail");
|
||||
/* for some reason simplelist doesn't allow adding items here if
|
||||
* info.get_name is given, so use normal list api */
|
||||
|
|
|
@ -409,7 +409,7 @@ static void read_viewers_config_init(void)
|
|||
|
||||
/* estimate bufsize with the filesize, will not be larger */
|
||||
strdup_bufsize = (size_t)filesz;
|
||||
strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops);
|
||||
strdup_handle = core_alloc_ex(strdup_bufsize, &ops);
|
||||
if(strdup_handle <= 0)
|
||||
goto out;
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ bool skin_backdrops_preload(void)
|
|||
}
|
||||
if (*filename && *filename != '-')
|
||||
{
|
||||
backdrops[i].buflib_handle = core_alloc_ex(filename, buf_size, &buflib_ops);
|
||||
backdrops[i].buflib_handle = core_alloc_ex(buf_size, &buflib_ops);
|
||||
if (backdrops[i].buflib_handle > 0)
|
||||
{
|
||||
backdrops[i].buffer = core_get_data(backdrops[i].buflib_handle);
|
||||
|
@ -287,8 +287,7 @@ void skin_backdrop_load_setting(void)
|
|||
if (backdrops[i].buflib_handle <= 0)
|
||||
{
|
||||
backdrops[i].buflib_handle =
|
||||
core_alloc_ex(global_settings.backdrop_file,
|
||||
LCD_BACKDROP_BYTES, &buflib_ops);
|
||||
core_alloc_ex(LCD_BACKDROP_BYTES, &buflib_ops);
|
||||
if (backdrops[i].buflib_handle <= 0)
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2574,8 +2574,7 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
|
|||
}
|
||||
#endif
|
||||
#ifndef __PCTOOL__
|
||||
wps_data->buflib_handle = core_alloc(isfile ? buf : "failsafe skin",
|
||||
skin_buffer_usage());
|
||||
wps_data->buflib_handle = core_alloc(skin_buffer_usage());
|
||||
if (wps_data->buflib_handle > 0)
|
||||
{
|
||||
wps_data->wps_loaded = true;
|
||||
|
|
|
@ -453,7 +453,7 @@ static void iap_malloc(void)
|
|||
return;
|
||||
|
||||
#ifdef IAP_MALLOC_DYNAMIC
|
||||
iap_buffer_handle = core_alloc_ex("iap", IAP_MALLOC_SIZE, &iap_buflib_callbacks);
|
||||
iap_buffer_handle = core_alloc_ex(IAP_MALLOC_SIZE, &iap_buflib_callbacks);
|
||||
if (iap_buffer_handle < 0)
|
||||
panicf("Could not allocate buffer memory");
|
||||
iap_buffers = core_get_data(iap_buffer_handle);
|
||||
|
|
|
@ -1606,9 +1606,7 @@ int core_load_bmp(const char * filename, struct bitmap *bm, const int bmformat,
|
|||
|
||||
if (buf_size > 0)
|
||||
{
|
||||
|
||||
handle = core_alloc_ex(filename, (size_t) buf_size, ops);
|
||||
|
||||
handle = core_alloc_ex(buf_size, ops);
|
||||
if (handle > 0)
|
||||
{
|
||||
core_pin(handle);
|
||||
|
|
|
@ -997,7 +997,7 @@ static void audio_reset_buffer(void)
|
|||
}
|
||||
if (core_allocatable() < (1 << 10))
|
||||
talk_buffer_set_policy(TALK_BUFFER_LOOSE); /* back off voice buffer */
|
||||
audiobuf_handle = core_alloc_maximum("audiobuf", &filebuflen, &ops);
|
||||
audiobuf_handle = core_alloc_maximum(&filebuflen, &ops);
|
||||
|
||||
if (audiobuf_handle > 0)
|
||||
audio_reset_buffer_noalloc(core_get_data(audiobuf_handle));
|
||||
|
|
|
@ -2020,7 +2020,7 @@ static void alloc_namebuffer(void)
|
|||
static int alloc_tempbuf(size_t* buflen)
|
||||
{
|
||||
/* request a reasonable size first */
|
||||
int handle = core_alloc_ex(NULL, PLAYLIST_LOAD_BUFLEN, &buflib_ops_locked);
|
||||
int handle = core_alloc_ex(PLAYLIST_LOAD_BUFLEN, &buflib_ops_locked);
|
||||
if (handle > 0)
|
||||
{
|
||||
*buflen = PLAYLIST_LOAD_BUFLEN;
|
||||
|
@ -2028,7 +2028,7 @@ static int alloc_tempbuf(size_t* buflen)
|
|||
}
|
||||
|
||||
/* otherwise, try being unreasonable */
|
||||
return core_alloc_maximum(NULL, buflen, &buflib_ops_locked);
|
||||
return core_alloc_maximum(buflen, &buflib_ops_locked);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2075,15 +2075,14 @@ void playlist_init(void)
|
|||
playlist->fd = -1;
|
||||
playlist->control_fd = -1;
|
||||
playlist->max_playlist_size = global_settings.max_files_in_playlist;
|
||||
handle = core_alloc_ex("playlist idx",
|
||||
playlist->max_playlist_size * sizeof(*playlist->indices), &ops);
|
||||
|
||||
handle = core_alloc_ex(playlist->max_playlist_size * sizeof(*playlist->indices), &ops);
|
||||
playlist->indices = core_get_data(handle);
|
||||
|
||||
initalize_new_playlist(playlist, true);
|
||||
|
||||
#ifdef HAVE_DIRCACHE
|
||||
handle = core_alloc_ex("playlist dc",
|
||||
handle = core_alloc_ex(
|
||||
playlist->max_playlist_size * sizeof(*playlist->dcfrefs), &ops);
|
||||
playlist->dcfrefs = core_get_data(handle);
|
||||
dc_copy_filerefs(playlist->dcfrefs, NULL, playlist->max_playlist_size);
|
||||
|
|
|
@ -585,7 +585,6 @@ static const struct plugin_api rockbox_api = {
|
|||
buflib_free,
|
||||
buflib_shrink,
|
||||
buflib_get_data,
|
||||
buflib_get_name,
|
||||
|
||||
/* sound */
|
||||
sound_set,
|
||||
|
@ -1039,8 +1038,7 @@ static void* plugin_get_audio_buffer(size_t *buffer_size)
|
|||
{
|
||||
if (plugin_buffer_handle <= 0)
|
||||
{
|
||||
plugin_buffer_handle = core_alloc_maximum("plugin audio buf",
|
||||
&plugin_buffer_size,
|
||||
plugin_buffer_handle = core_alloc_maximum(&plugin_buffer_size,
|
||||
&buflib_ops_locked);
|
||||
}
|
||||
|
||||
|
|
|
@ -649,8 +649,8 @@ struct plugin_api {
|
|||
size_t (*buflib_available)(struct buflib_context* ctx);
|
||||
int (*buflib_alloc)(struct buflib_context* ctx, size_t size);
|
||||
int (*buflib_alloc_ex)(struct buflib_context* ctx, size_t size,
|
||||
const char* name, struct buflib_callbacks *ops);
|
||||
int (*buflib_alloc_maximum)(struct buflib_context* ctx, const char* name,
|
||||
struct buflib_callbacks *ops);
|
||||
int (*buflib_alloc_maximum)(struct buflib_context* ctx,
|
||||
size_t* size, struct buflib_callbacks *ops);
|
||||
void (*buflib_buffer_in)(struct buflib_context* ctx, int size);
|
||||
void* (*buflib_buffer_out)(struct buflib_context* ctx, size_t* size);
|
||||
|
@ -658,7 +658,6 @@ struct plugin_api {
|
|||
bool (*buflib_shrink)(struct buflib_context* ctx, int handle,
|
||||
void* new_start, size_t new_size);
|
||||
void* (*buflib_get_data)(struct buflib_context* ctx, int handle);
|
||||
const char* (*buflib_get_name)(struct buflib_context* ctx, int handle);
|
||||
|
||||
/* sound */
|
||||
void (*sound_set)(int setting, int value);
|
||||
|
|
|
@ -202,7 +202,7 @@ void radioart_init(bool entering_screen)
|
|||
{
|
||||
/* grab control over buffering */
|
||||
size_t bufsize;
|
||||
int handle = core_alloc_maximum("radioart", &bufsize, &radioart_ops);
|
||||
int handle = core_alloc_maximum(&bufsize, &radioart_ops);
|
||||
if (handle <0)
|
||||
{
|
||||
splash(HZ, "Radioart Failed - OOM");
|
||||
|
|
|
@ -64,7 +64,7 @@ bool tdspeed_alloc_buffers(int32_t **buffers, const int *buf_s, int nbuf)
|
|||
{
|
||||
if (handles[i] <= 0)
|
||||
{
|
||||
handles[i] = core_alloc_ex("tdspeed", buf_s[i], &ops);
|
||||
handles[i] = core_alloc_ex(buf_s[i], &ops);
|
||||
|
||||
if (handles[i] <= 0)
|
||||
return false;
|
||||
|
|
|
@ -1408,7 +1408,7 @@ static void on_init_recording(void)
|
|||
send_event(RECORDING_EVENT_START, NULL);
|
||||
/* FIXME: This buffer should play nicer and be shrinkable/movable */
|
||||
talk_buffer_set_policy(TALK_BUFFER_LOOSE);
|
||||
pcmrec_handle = core_alloc_maximum("pcmrec", &rec_buffer_size, &buflib_ops_locked);
|
||||
pcmrec_handle = core_alloc_maximum(&rec_buffer_size, &buflib_ops_locked);
|
||||
if (pcmrec_handle <= 0)
|
||||
/* someone is abusing core_alloc_maximum(). Fix this evil guy instead of
|
||||
* trying to handle OOM without hope */
|
||||
|
|
|
@ -128,8 +128,7 @@ static struct shortcut* get_shortcut(int index)
|
|||
|
||||
if (first_handle == 0)
|
||||
{
|
||||
first_handle = core_alloc_ex("shortcuts_head",
|
||||
sizeof(struct shortcut_handle), &shortcut_ops);
|
||||
first_handle = core_alloc_ex(sizeof(struct shortcut_handle), &shortcut_ops);
|
||||
if (first_handle <= 0)
|
||||
return NULL;
|
||||
h = core_get_data(first_handle);
|
||||
|
@ -146,11 +145,9 @@ static struct shortcut* get_shortcut(int index)
|
|||
} while (handle_count > 0 && current_handle > 0);
|
||||
if (handle_count > 0 && handle_index == 0)
|
||||
{
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof buf, "shortcuts_%d", index/SHORTCUTS_PER_HANDLE);
|
||||
/* prevent invalidation of 'h' during compaction */
|
||||
++buflib_move_lock;
|
||||
h->next_handle = core_alloc_ex(buf, sizeof(struct shortcut_handle), &shortcut_ops);
|
||||
h->next_handle = core_alloc_ex(sizeof(struct shortcut_handle), &shortcut_ops);
|
||||
--buflib_move_lock;
|
||||
if (h->next_handle <= 0)
|
||||
return NULL;
|
||||
|
@ -390,7 +387,7 @@ void shortcuts_init(void)
|
|||
fd = open_utf8(SHORTCUTS_FILENAME, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return;
|
||||
first_handle = core_alloc_ex("shortcuts_head", sizeof(struct shortcut_handle), &shortcut_ops);
|
||||
first_handle = core_alloc_ex(sizeof(struct shortcut_handle), &shortcut_ops);
|
||||
if (first_handle <= 0) {
|
||||
close(fd);
|
||||
return;
|
||||
|
|
|
@ -410,7 +410,7 @@ static void allocate_tempbuf(void)
|
|||
#else /* !__PCTOOL__ */
|
||||
/* Need to pass dummy ops to prevent the buffer being moved
|
||||
* out from under us, since we yield during the tagcache commit. */
|
||||
tempbuf_handle = core_alloc_maximum("tc tempbuf", &size, &buflib_ops_locked);
|
||||
tempbuf_handle = core_alloc_maximum(&size, &buflib_ops_locked);
|
||||
if (tempbuf_handle > 0)
|
||||
{
|
||||
tempbuf = core_get_data(tempbuf_handle);
|
||||
|
@ -4115,7 +4115,7 @@ static bool allocate_tagcache(void)
|
|||
alloc_size += tcmh.tch.entry_count*sizeof(struct dircache_fileref);
|
||||
#endif
|
||||
|
||||
int handle = core_alloc_ex("tc ramcache", alloc_size, &ops);
|
||||
int handle = core_alloc_ex(alloc_size, &ops);
|
||||
if (handle <= 0)
|
||||
return false;
|
||||
|
||||
|
@ -4158,7 +4158,7 @@ static bool tagcache_dumpload(void)
|
|||
}
|
||||
|
||||
/* Lets allocate real memory and load it */
|
||||
handle = core_alloc_ex("tc ramcache", shdr.tc_stat.ramcache_allocated, &ops);
|
||||
handle = core_alloc_ex(shdr.tc_stat.ramcache_allocated, &ops);
|
||||
if (handle <= 0)
|
||||
{
|
||||
logf("alloc failure");
|
||||
|
|
|
@ -1255,7 +1255,7 @@ static bool initialize_tagtree(void) /* also used when user selects 'Reload' in
|
|||
menu_count = 0;
|
||||
menu = NULL;
|
||||
rootmenu = -1;
|
||||
tagtree_handle = core_alloc_maximum("tagtree", &tagtree_bufsize, &ops);
|
||||
tagtree_handle = core_alloc_maximum(&tagtree_bufsize, &ops);
|
||||
if (tagtree_handle < 0)
|
||||
panicf("tagtree OOM");
|
||||
|
||||
|
|
|
@ -496,7 +496,7 @@ static bool load_index_table(int fd, const struct voicefile_header *hdr)
|
|||
return true;
|
||||
|
||||
ssize_t alloc_size = (hdr->id1_max + hdr->id2_max) * sizeof(struct clip_entry);
|
||||
index_handle = core_alloc_ex("voice index", alloc_size, &talk_ops);
|
||||
index_handle = core_alloc_ex(alloc_size, &talk_ops);
|
||||
if (index_handle < 0)
|
||||
return false;
|
||||
|
||||
|
@ -536,7 +536,7 @@ static bool load_header(int fd, struct voicefile_header *hdr)
|
|||
static bool create_clip_buffer(size_t max_size)
|
||||
{
|
||||
/* just allocate, populate on an as-needed basis later */
|
||||
talk_handle = core_alloc_ex("voice data", max_size, &talk_ops);
|
||||
talk_handle = core_alloc_ex(max_size, &talk_ops);
|
||||
if (talk_handle < 0)
|
||||
goto alloc_err;
|
||||
|
||||
|
|
|
@ -1063,14 +1063,11 @@ void tree_mem_init(void)
|
|||
|
||||
cache->name_buffer_size = AVERAGE_FILENAME_LENGTH *
|
||||
global_settings.max_files_in_dir;
|
||||
cache->name_buffer_handle = core_alloc_ex("tree names",
|
||||
cache->name_buffer_size,
|
||||
&ops);
|
||||
cache->name_buffer_handle = core_alloc_ex(cache->name_buffer_size, &ops);
|
||||
|
||||
cache->max_entries = global_settings.max_files_in_dir;
|
||||
cache->entries_handle = core_alloc_ex("tree entries",
|
||||
cache->max_entries*(sizeof(struct entry)),
|
||||
&ops);
|
||||
cache->entries_handle =
|
||||
core_alloc_ex(cache->max_entries*(sizeof(struct entry)), &ops);
|
||||
}
|
||||
|
||||
bool bookmark_play(char *resume_file, int index, unsigned long elapsed,
|
||||
|
|
|
@ -569,7 +569,7 @@ void voice_thread_init(void)
|
|||
if (voice_thread_id != 0)
|
||||
return; /* Already did an init and succeeded at it */
|
||||
|
||||
voice_buf_hid = core_alloc_ex("voice buf", sizeof (*voice_buf), &ops);
|
||||
voice_buf_hid = core_alloc_ex(sizeof (*voice_buf), &ops);
|
||||
|
||||
if (voice_buf_hid <= 0)
|
||||
{
|
||||
|
|
|
@ -72,7 +72,7 @@ static int read_linux_args(const char* filename)
|
|||
int ret;
|
||||
|
||||
size_t max_size;
|
||||
int handle = core_alloc_maximum("args", &max_size, &buflib_ops_locked);
|
||||
int handle = core_alloc_maximum(&max_size, &buflib_ops_locked);
|
||||
if(handle <= 0) {
|
||||
splashf(5*HZ, "Out of memory");
|
||||
return -2;
|
||||
|
|
|
@ -103,7 +103,7 @@ int load_rockbox(const char* filename, size_t* sizep)
|
|||
if(check_disk(true) != DISK_PRESENT)
|
||||
return -1;
|
||||
|
||||
int handle = core_alloc_maximum("rockbox", sizep, &buflib_ops_locked);
|
||||
int handle = core_alloc_maximum(sizep, &buflib_ops_locked);
|
||||
if(handle < 0) {
|
||||
splashf(5*HZ, "Out of memory");
|
||||
return -2;
|
||||
|
|
|
@ -633,7 +633,7 @@ buflib_buffer_in(struct buflib_context *ctx, int size)
|
|||
int
|
||||
buflib_alloc(struct buflib_context *ctx, size_t size)
|
||||
{
|
||||
return buflib_alloc_ex(ctx, size, NULL, NULL);
|
||||
return buflib_alloc_ex(ctx, size, NULL);
|
||||
}
|
||||
|
||||
/* Allocate a buffer of size bytes, returning a handle for it.
|
||||
|
@ -647,11 +647,9 @@ buflib_alloc(struct buflib_context *ctx, size_t size)
|
|||
*/
|
||||
|
||||
int
|
||||
buflib_alloc_ex(struct buflib_context *ctx, size_t size, const char *name,
|
||||
buflib_alloc_ex(struct buflib_context *ctx, size_t size,
|
||||
struct buflib_callbacks *ops)
|
||||
{
|
||||
(void)name;
|
||||
|
||||
union buflib_data *handle, *block;
|
||||
bool last;
|
||||
/* This really is assigned a value before use */
|
||||
|
@ -943,7 +941,7 @@ buflib_available(struct buflib_context* ctx)
|
|||
* serviced anyway).
|
||||
*/
|
||||
int
|
||||
buflib_alloc_maximum(struct buflib_context* ctx, const char* name, size_t *size, struct buflib_callbacks *ops)
|
||||
buflib_alloc_maximum(struct buflib_context* ctx, size_t *size, struct buflib_callbacks *ops)
|
||||
{
|
||||
/* ignore ctx->compact because it's true if all movable blocks are contiguous
|
||||
* even if the buffer has holes due to unmovable allocations */
|
||||
|
@ -960,7 +958,7 @@ buflib_alloc_maximum(struct buflib_context* ctx, const char* name, size_t *size,
|
|||
if (*size <= 0) /* OOM */
|
||||
return -1;
|
||||
|
||||
return buflib_alloc_ex(ctx, *size, name, ops);
|
||||
return buflib_alloc_ex(ctx, *size, ops);
|
||||
}
|
||||
|
||||
/* Shrink the allocation indicated by the handle according to new_start and
|
||||
|
@ -1073,13 +1071,6 @@ unsigned buflib_pin_count(struct buflib_context *ctx, int handle)
|
|||
return data[-bidx_PIN].pincount;
|
||||
}
|
||||
|
||||
const char* buflib_get_name(struct buflib_context *ctx, int handle)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)handle;
|
||||
return "";
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
void *buflib_get_data(struct buflib_context *ctx, int handle)
|
||||
|
|
|
@ -479,7 +479,7 @@ static void binding_dissolve_volume(struct dircache_runinfo_volume *dcrivolp)
|
|||
static int alloc_cache(size_t size)
|
||||
{
|
||||
/* pad with one extra-- see alloc_name() and free_name() */
|
||||
return core_alloc_ex("dircache", size + 1, &dircache_runinfo.ops);
|
||||
return core_alloc_ex(size + 1, &dircache_runinfo.ops);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -166,15 +166,15 @@ static unsigned short default_cp_table_buf[MAX_CP_TABLE_SIZE+1];
|
|||
default_cp_table_buf
|
||||
#define cp_table_free(handle) \
|
||||
do {} while (0)
|
||||
#define cp_table_alloc(filename, size, opsp) \
|
||||
#define cp_table_alloc(size, opsp) \
|
||||
({ (void)(opsp); 1; })
|
||||
#define cp_table_pin(handle) \
|
||||
do { (void)handle; } while(0)
|
||||
#define cp_table_unpin(handle) \
|
||||
do { (void)handle; } while(0)
|
||||
#else
|
||||
#define cp_table_alloc(filename, size, opsp) \
|
||||
core_alloc_ex((filename), (size), (opsp))
|
||||
#define cp_table_alloc(size, opsp) \
|
||||
core_alloc_ex((size), (opsp))
|
||||
#define cp_table_free(handle) \
|
||||
core_free(handle)
|
||||
#define cp_table_get_data(handle) \
|
||||
|
@ -223,7 +223,7 @@ static int alloc_and_load_cp_table(int cp, void *buf)
|
|||
!(size % (off_t)sizeof (uint16_t))) {
|
||||
|
||||
/* if the buffer is provided, use that but don't alloc */
|
||||
int handle = buf ? 0 : cp_table_alloc(filename, size, NULL);
|
||||
int handle = buf ? 0 : cp_table_alloc(size, NULL);
|
||||
if (handle > 0) {
|
||||
cp_table_pin(handle);
|
||||
buf = cp_table_get_data(handle);
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "crc32.h"
|
||||
#include "rbendian.h"
|
||||
|
||||
#define zip_core_alloc(N) core_alloc_ex("zip",(N),&buflib_ops_locked)
|
||||
#define zip_core_alloc(N) core_alloc_ex((N),&buflib_ops_locked)
|
||||
|
||||
enum {
|
||||
ZIP_SIG_ED = 0x06054b50,
|
||||
|
|
|
@ -51,7 +51,7 @@ void core_allocator_init(void)
|
|||
|
||||
buflib_init(&core_ctx, start, audiobufend - start);
|
||||
|
||||
test_alloc = core_alloc("test", 112);
|
||||
test_alloc = core_alloc(112);
|
||||
}
|
||||
|
||||
bool core_test_free(void)
|
||||
|
@ -69,14 +69,14 @@ bool core_test_free(void)
|
|||
* Note: Buffers allocated by this functions are movable.
|
||||
* Don't pass them to functions that call yield()
|
||||
* like disc input/output. */
|
||||
int core_alloc(const char* name, size_t size)
|
||||
int core_alloc(size_t size)
|
||||
{
|
||||
return buflib_alloc_ex(&core_ctx, size, name, NULL);
|
||||
return buflib_alloc_ex(&core_ctx, size, NULL);
|
||||
}
|
||||
|
||||
int core_alloc_ex(const char* name, size_t size, struct buflib_callbacks *ops)
|
||||
int core_alloc_ex(size_t size, struct buflib_callbacks *ops)
|
||||
{
|
||||
return buflib_alloc_ex(&core_ctx, size, name, ops);
|
||||
return buflib_alloc_ex(&core_ctx, size, ops);
|
||||
}
|
||||
|
||||
size_t core_available(void)
|
||||
|
@ -94,9 +94,9 @@ int core_free(int handle)
|
|||
return buflib_free(&core_ctx, handle);
|
||||
}
|
||||
|
||||
int core_alloc_maximum(const char* name, size_t *size, struct buflib_callbacks *ops)
|
||||
int core_alloc_maximum(size_t *size, struct buflib_callbacks *ops)
|
||||
{
|
||||
return buflib_alloc_maximum(&core_ctx, name, size, ops);
|
||||
return buflib_alloc_maximum(&core_ctx, size, ops);
|
||||
}
|
||||
|
||||
bool core_shrink(int handle, void* new_start, size_t new_size)
|
||||
|
@ -119,12 +119,6 @@ unsigned core_pin_count(int handle)
|
|||
return buflib_pin_count(&core_ctx, handle);
|
||||
}
|
||||
|
||||
const char* core_get_name(int handle)
|
||||
{
|
||||
const char *name = buflib_get_name(&core_ctx, handle);
|
||||
return name ?: "<anonymous>";
|
||||
}
|
||||
|
||||
int core_get_num_blocks(void)
|
||||
{
|
||||
return buflib_get_num_blocks(&core_ctx);
|
||||
|
|
|
@ -525,7 +525,7 @@ int font_load_ex( const char *path, size_t buf_size, int glyphs )
|
|||
font_id = open_slot;
|
||||
|
||||
/* allocate mem */
|
||||
int handle = core_alloc_ex( NULL,
|
||||
int handle = core_alloc_ex(
|
||||
bufsize + sizeof( struct buflib_alloc_data ),
|
||||
&buflibops );
|
||||
if ( handle <= 0 )
|
||||
|
|
|
@ -62,8 +62,7 @@ struct buflib_context
|
|||
* to the actually requested number of bytes.
|
||||
*
|
||||
* The total number of bytes consumed by an allocation is
|
||||
* BUFLIB_ALLOC_OVERHEAD + requested bytes + strlen(<name passed to
|
||||
* buflib_alloc_ex()) + pad to pointer size
|
||||
* BUFLIB_ALLOC_OVERHEAD + requested bytes + pad to pointer size
|
||||
*/
|
||||
#define BUFLIB_ALLOC_OVERHEAD (5*sizeof(union buflib_data))
|
||||
|
||||
|
@ -215,7 +214,6 @@ int buflib_alloc(struct buflib_context *context, size_t size);
|
|||
* Allocates memory from the buflib's memory pool with additional callbacks
|
||||
* and flags
|
||||
*
|
||||
* name: A string identifier giving this allocation a name
|
||||
* size: How many bytes to allocate
|
||||
* ops: a struct with pointers to callback functions (see above).
|
||||
* if "ops" is NULL: Buffer is movable.
|
||||
|
@ -223,7 +221,7 @@ int buflib_alloc(struct buflib_context *context, size_t size);
|
|||
* Returns: A positive integer handle identifying this allocation, or
|
||||
* a negative value on error (0 is also not a valid handle)
|
||||
*/
|
||||
int buflib_alloc_ex(struct buflib_context *ctx, size_t size, const char *name,
|
||||
int buflib_alloc_ex(struct buflib_context *ctx, size_t size,
|
||||
struct buflib_callbacks *ops);
|
||||
|
||||
|
||||
|
@ -241,15 +239,14 @@ int buflib_alloc_ex(struct buflib_context *ctx, size_t size, const char *name,
|
|||
* and even shrinks other allocations. However, do not depend on this behavior,
|
||||
* it may change.
|
||||
*
|
||||
* name: A string identifier giving this allocation a name
|
||||
* size: The actual size will be returned into size
|
||||
* ops: a struct with pointers to callback functions
|
||||
*
|
||||
* Returns: A positive integer handle identifying this allocation, or
|
||||
* a negative value on error (0 is also not a valid handle)
|
||||
*/
|
||||
int buflib_alloc_maximum(struct buflib_context* ctx, const char* name,
|
||||
size_t *size, struct buflib_callbacks *ops);
|
||||
int buflib_alloc_maximum(struct buflib_context* ctx,
|
||||
size_t *size, struct buflib_callbacks *ops);
|
||||
|
||||
/**
|
||||
* Queries the data pointer for the given handle. It's actually a cheap
|
||||
|
@ -348,18 +345,6 @@ void buflib_buffer_in(struct buflib_context *ctx, int size);
|
|||
|
||||
/* debugging */
|
||||
|
||||
/**
|
||||
* Returns the name, as given to buflib_alloc() and buflib_allloc_ex(), of the
|
||||
* allocation associated with the given handle. As naming allocations
|
||||
* is optional, there might be no name associated.
|
||||
*
|
||||
* handle: The handle indicating the allocation
|
||||
*
|
||||
* Returns: A pointer to the string identifier of the allocation, or NULL
|
||||
* if none was specified with buflib_alloc_ex().
|
||||
*/
|
||||
const char* buflib_get_name(struct buflib_context *ctx, int handle);
|
||||
|
||||
/**
|
||||
* Gets the number of blocks in the entire buffer, allocated or unallocated
|
||||
*
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
* they have a predefined context
|
||||
*/
|
||||
void core_allocator_init(void) INIT_ATTR;
|
||||
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);
|
||||
int core_alloc(size_t size);
|
||||
int core_alloc_ex(size_t size, struct buflib_callbacks *ops);
|
||||
int core_alloc_maximum(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);
|
||||
|
@ -21,7 +21,6 @@ unsigned core_pin_count(int handle);
|
|||
int core_free(int handle);
|
||||
size_t core_available(void);
|
||||
size_t core_allocatable(void);
|
||||
const char* core_get_name(int handle);
|
||||
#ifdef DEBUG
|
||||
void core_check_valid(void);
|
||||
#endif
|
||||
|
|
|
@ -80,7 +80,7 @@ static int uimage_alloc_state(const struct uimage_header* uh)
|
|||
#ifdef HAVE_UIMAGE_COMP_GZIP
|
||||
case IH_COMP_GZIP:
|
||||
size = inflate_size + inflate_align - 1;
|
||||
return core_alloc_ex("inflate", size, &buflib_ops_locked);
|
||||
return core_alloc_ex(size, &buflib_ops_locked);
|
||||
#endif
|
||||
|
||||
default:
|
||||
|
@ -206,7 +206,7 @@ int uimage_load(struct uimage_header* uh, size_t* out_size,
|
|||
return E_OUT_OF_MEMORY;
|
||||
|
||||
*out_size = 0;
|
||||
int out_h = core_alloc_maximum("uimage", out_size, &buflib_ops_locked);
|
||||
int out_h = core_alloc_maximum(out_size, &buflib_ops_locked);
|
||||
if(out_h <= 0) {
|
||||
ret = E_OUT_OF_MEMORY;
|
||||
goto err;
|
||||
|
|
|
@ -239,7 +239,7 @@ int rolo_load(const char* filename)
|
|||
|
||||
/* get the system buffer. release only in case of error, otherwise
|
||||
* we don't return anyway */
|
||||
rolo_handle = core_alloc_maximum("rolo", &filebuf_size, &buflib_ops_locked);
|
||||
rolo_handle = core_alloc_maximum(&filebuf_size, &buflib_ops_locked);
|
||||
if (rolo_handle < 0)
|
||||
{
|
||||
rolo_error("OOM");
|
||||
|
|
|
@ -915,7 +915,7 @@ int nand_init(void)
|
|||
#ifndef BOOTLOADER
|
||||
/* Use chip info to allocate the correct size LPT buffer */
|
||||
lptbuf_size = sizeof(struct lpt_entry) * segments_per_bank * total_banks;
|
||||
lpt_handle = core_alloc("lpt lookup", lptbuf_size);
|
||||
lpt_handle = core_alloc(lptbuf_size);
|
||||
struct lpt_entry* lpt_lookup = core_get_data(lpt_handle);
|
||||
#else
|
||||
/* Use a static array in the bootloader */
|
||||
|
|
|
@ -303,7 +303,7 @@ static void cfs_init(void)
|
|||
_ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inodes_nr[1]), 1, §or);
|
||||
inode = (struct cfs_inode*)§or;
|
||||
#ifndef BOOTLOADER
|
||||
sectors_handle = core_alloc("ata sectors", VFAT_SECTOR_SIZE(inode->filesize));
|
||||
sectors_handle = core_alloc(VFAT_SECTOR_SIZE(inode->filesize));
|
||||
unsigned long *sectors = core_get_data(sectors_handle);
|
||||
#else
|
||||
static unsigned long _sector[VFAT_SECTOR_SIZE(1024*1024*1024)]; /* 1GB guess */
|
||||
|
|
|
@ -151,7 +151,7 @@ static int updater_init(struct updater* u)
|
|||
|
||||
/* buf_len is a bit oversized here, but it's not really important */
|
||||
u->buf_len = u->img_len + sizeof(mtar_t) + 2*CACHEALIGN_SIZE;
|
||||
u->buf_hnd = core_alloc_ex("boot_image", u->buf_len, &buflib_ops_locked);
|
||||
u->buf_hnd = core_alloc_ex(u->buf_len, &buflib_ops_locked);
|
||||
if(u->buf_hnd < 0) {
|
||||
rc = IERR_OUT_OF_MEMORY;
|
||||
goto error;
|
||||
|
|
|
@ -451,8 +451,7 @@ void usb_storage_init_connection(void)
|
|||
unsigned char * buffer;
|
||||
|
||||
// Add 31 to handle worst-case misalignment
|
||||
usb_handle = core_alloc_ex("usb storage",
|
||||
ALLOCATE_BUFFER_SIZE + MAX_CBW_SIZE + 31,
|
||||
usb_handle = core_alloc_ex(ALLOCATE_BUFFER_SIZE + MAX_CBW_SIZE + 31,
|
||||
&buflib_ops_locked);
|
||||
if (usb_handle < 0)
|
||||
panicf("%s(): OOM", __func__);
|
||||
|
|
|
@ -49,7 +49,7 @@ static int handle = -1;
|
|||
|
||||
static int pbe_buffer_alloc(void)
|
||||
{
|
||||
handle = core_alloc("dsp_pbe_buffer", PBE_BUFSIZE);
|
||||
handle = core_alloc(PBE_BUFSIZE);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ static int handle = -1;
|
|||
|
||||
static int surround_buffer_alloc(void)
|
||||
{
|
||||
handle = core_alloc("dsp_surround_buffer", SURROUND_BUFSIZE);
|
||||
handle = core_alloc(SURROUND_BUFSIZE);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue