core_alloc: Provide a tiny test allocation, which can be freed for debug purposes.

This allocation can be freed in the buflib debug menu (select it to free).
Doing a another allocation, e.g. by selecting another item in this debug menu
will cause compaction (all allocs move).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30719 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2011-10-05 18:32:19 +00:00
parent 6efb3f0760
commit 4478b25ede
3 changed files with 33 additions and 8 deletions

View file

@ -428,6 +428,12 @@ static const char* bf_getname(int selected_item, void *data,
static int bf_action_cb(int action, struct gui_synclist* list)
{
if (action == ACTION_STD_OK)
{
if (gui_synclist_get_sel_pos(list) == 0 && core_test_free())
{
splash(HZ, "Freed test handle. New alloc should trigger compact");
}
else
{
splash(HZ/1, "Attempting a 64k allocation");
int handle = core_alloc("test", 64<<10);
@ -437,6 +443,7 @@ static int bf_action_cb(int action, struct gui_synclist* list)
gui_synclist_set_nb_items(list, core_get_num_blocks());
if (handle > 0)
core_free(handle);
}
action = ACTION_REDRAW;
}
else if (action == ACTION_NONE)

View file

@ -6,6 +6,9 @@
/* not static so it can be discovered by core_get_data() */
struct buflib_context core_ctx;
/* debug test alloc */
static int test_alloc;
void core_allocator_init(void)
{
buffer_init();
@ -13,6 +16,17 @@ void core_allocator_init(void)
void *start = buffer_get_buffer(&size);
buflib_init(&core_ctx, start, size);
buffer_release_buffer(size);
test_alloc = core_alloc("test", 112);
}
bool core_test_free(void)
{
bool ret = test_alloc > 0;
if (ret)
test_alloc = core_free(test_alloc);
return ret;
}
int core_alloc(const char* name, size_t size)

View file

@ -28,6 +28,10 @@ int core_get_num_blocks(void);
void core_print_block_at(int block_num, char* buf, size_t bufsize);
#endif
/* frees the debug test alloc created at initialization,
* since this is the first any further alloc should force a compaction run */
bool core_test_free(void);
static inline void* core_get_data(int handle)
{
extern struct buflib_context core_ctx;