summaryrefslogtreecommitdiffstats
path: root/apps/tree.h
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-30 14:01:45 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-30 14:01:45 +0000
commitbaa070cca6d459a7c5aed81f29e4cc4f6c7410b3 (patch)
tree5123360aea420b96e4a97a8e88cf51b4277152d9 /apps/tree.h
parentd0b72e25903574acb1cf9184a6052cdd646dbc37 (diff)
downloadrockbox-baa070cca6d459a7c5aed81f29e4cc4f6c7410b3.tar.gz
rockbox-baa070cca6d459a7c5aed81f29e4cc4f6c7410b3.tar.bz2
rockbox-baa070cca6d459a7c5aed81f29e4cc4f6c7410b3.zip
GSoC/Buflib: Enable compaction in buflib.
This enables the ability to allocate (and free) memory dynamically without fragmentation, through compaction. This means allocations can move and fragmentation be reduced. Most changes are preparing Rockbox for this, which many times means adding a move callback which can temporarily disable movement when the corresponding code is in a critical section. For now, the audio buffer allocation has a central role, because it's the one having allocated most. This buffer is able to shrink itself, for which it needs to stop playback for a very short moment. For this, audio_buffer_available() returns the size of the audio buffer which can possibly be used by other allocations because the audio buffer can shrink. lastfm scrobbling and timestretch can now be toggled at runtime without requiring a reboot. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30381 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/tree.h')
-rw-r--r--apps/tree.h36
1 files changed, 26 insertions, 10 deletions
diff --git a/apps/tree.h b/apps/tree.h
index c07b92f298..2b296050d3 100644
--- a/apps/tree.h
+++ b/apps/tree.h
@@ -26,26 +26,30 @@
#include <file.h>
#include "icon.h"
+/* keep this struct compatible (total size and name member)
+ * with struct tagtree_entry (tagtree.h) */
struct entry {
- short attr; /* FAT attributes + file type flags */
- unsigned long time_write; /* Last write time */
char *name;
+ int attr; /* FAT attributes + file type flags */
+ unsigned time_write; /* Last write time */
};
-
#define BROWSE_SELECTONLY 0x0001 /* exit on selecting a file */
#define BROWSE_NO_CONTEXT_MENU 0x0002 /* disable context menu */
#define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */
struct tree_context;
+
struct tree_cache {
- /* A big buffer with plenty of entry structs,
- * contains all files and dirs in the current
- * dir (with filters applied) */
- void* entries;
- char* name_buffer;
- int max_entries; /* Max entries in the cache */
- int name_buffer_size; /* in bytes */
+ /* A big buffer with plenty of entry structs, contains all files and dirs
+ * in the current dir (with filters applied)
+ * Note that they're buflib-allocated and can therefore possibly move
+ * They need to be locked if used around yielding functions */
+ int entries_handle; /* handle to the entry cache */
+ int name_buffer_handle; /* handle to the name cache */
+ int max_entries; /* Max entries in the cache */
+ int name_buffer_size; /* in bytes */
+ volatile int lock_count; /* non-0 if buffers may not move */
};
struct browse_context {
@@ -95,6 +99,10 @@ struct tree_context {
struct browse_context *browse;
};
+/*
+ * Call one of the two below after yields since the entrys may move inbetween */
+struct entry* tree_get_entries(struct tree_context *t);
+struct entry* tree_get_entry_at(struct tree_context *t, int index);
void tree_drawlists(void);
void tree_mem_init(void) INIT_ATTR;
void tree_gui_init(void) INIT_ATTR;
@@ -108,6 +116,14 @@ void browse_context_init(struct browse_context *browse,
int rockbox_browse(struct browse_context *browse);
bool create_playlist(void);
void resume_directory(const char *dir);
+static inline void tree_lock_cache(struct tree_context *t)
+{
+ t->cache.lock_count++;
+}
+static inline void tree_unlock_cache(struct tree_context *t)
+{
+ t->cache.lock_count--;
+}
#ifdef WIN32
/* it takes an int on windows */
#define getcwd_size_t int