diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-10-05 18:32:19 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-10-05 18:32:19 +0000 |
commit | 4478b25ede0129b1572145737627db7297dcc89f (patch) | |
tree | 26e30d0021ee7d3433ec055c4576cb24f14d9080 | |
parent | 6efb3f0760b54fb80423924a7aab17da043dbba9 (diff) | |
download | rockbox-4478b25ede0129b1572145737627db7297dcc89f.tar.gz rockbox-4478b25ede0129b1572145737627db7297dcc89f.zip |
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
-rw-r--r-- | apps/debug_menu.c | 23 | ||||
-rw-r--r-- | firmware/core_alloc.c | 14 | ||||
-rw-r--r-- | firmware/include/core_alloc.h | 4 |
3 files changed, 33 insertions, 8 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 7c2e6c7870..e96b8c553f 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -429,14 +429,21 @@ static int bf_action_cb(int action, struct gui_synclist* list) | |||
429 | { | 429 | { |
430 | if (action == ACTION_STD_OK) | 430 | if (action == ACTION_STD_OK) |
431 | { | 431 | { |
432 | splash(HZ/1, "Attempting a 64k allocation"); | 432 | if (gui_synclist_get_sel_pos(list) == 0 && core_test_free()) |
433 | int handle = core_alloc("test", 64<<10); | 433 | { |
434 | splash(HZ/2, (handle > 0) ? "Success":"Fail"); | 434 | splash(HZ, "Freed test handle. New alloc should trigger compact"); |
435 | /* for some reason simplelist doesn't allow adding items here if | 435 | } |
436 | * info.get_name is given, so use normal list api */ | 436 | else |
437 | gui_synclist_set_nb_items(list, core_get_num_blocks()); | 437 | { |
438 | if (handle > 0) | 438 | splash(HZ/1, "Attempting a 64k allocation"); |
439 | core_free(handle); | 439 | int handle = core_alloc("test", 64<<10); |
440 | splash(HZ/2, (handle > 0) ? "Success":"Fail"); | ||
441 | /* for some reason simplelist doesn't allow adding items here if | ||
442 | * info.get_name is given, so use normal list api */ | ||
443 | gui_synclist_set_nb_items(list, core_get_num_blocks()); | ||
444 | if (handle > 0) | ||
445 | core_free(handle); | ||
446 | } | ||
440 | action = ACTION_REDRAW; | 447 | action = ACTION_REDRAW; |
441 | } | 448 | } |
442 | else if (action == ACTION_NONE) | 449 | else if (action == ACTION_NONE) |
diff --git a/firmware/core_alloc.c b/firmware/core_alloc.c index 2250f5c664..21dd1319dd 100644 --- a/firmware/core_alloc.c +++ b/firmware/core_alloc.c | |||
@@ -6,6 +6,9 @@ | |||
6 | 6 | ||
7 | /* not static so it can be discovered by core_get_data() */ | 7 | /* not static so it can be discovered by core_get_data() */ |
8 | struct buflib_context core_ctx; | 8 | struct buflib_context core_ctx; |
9 | |||
10 | /* debug test alloc */ | ||
11 | static int test_alloc; | ||
9 | void core_allocator_init(void) | 12 | void core_allocator_init(void) |
10 | { | 13 | { |
11 | buffer_init(); | 14 | buffer_init(); |
@@ -13,6 +16,17 @@ void core_allocator_init(void) | |||
13 | void *start = buffer_get_buffer(&size); | 16 | void *start = buffer_get_buffer(&size); |
14 | buflib_init(&core_ctx, start, size); | 17 | buflib_init(&core_ctx, start, size); |
15 | buffer_release_buffer(size); | 18 | buffer_release_buffer(size); |
19 | |||
20 | test_alloc = core_alloc("test", 112); | ||
21 | } | ||
22 | |||
23 | bool core_test_free(void) | ||
24 | { | ||
25 | bool ret = test_alloc > 0; | ||
26 | if (ret) | ||
27 | test_alloc = core_free(test_alloc); | ||
28 | |||
29 | return ret; | ||
16 | } | 30 | } |
17 | 31 | ||
18 | int core_alloc(const char* name, size_t size) | 32 | int core_alloc(const char* name, size_t size) |
diff --git a/firmware/include/core_alloc.h b/firmware/include/core_alloc.h index b2edec5377..0ac7e5b73d 100644 --- a/firmware/include/core_alloc.h +++ b/firmware/include/core_alloc.h | |||
@@ -28,6 +28,10 @@ int core_get_num_blocks(void); | |||
28 | void core_print_block_at(int block_num, char* buf, size_t bufsize); | 28 | void core_print_block_at(int block_num, char* buf, size_t bufsize); |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | /* frees the debug test alloc created at initialization, | ||
32 | * since this is the first any further alloc should force a compaction run */ | ||
33 | bool core_test_free(void); | ||
34 | |||
31 | static inline void* core_get_data(int handle) | 35 | static inline void* core_get_data(int handle) |
32 | { | 36 | { |
33 | extern struct buflib_context core_ctx; | 37 | extern struct buflib_context core_ctx; |