summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-14 15:13:00 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-14 15:13:00 +0000
commitd1322b71595336740eb5e18e5deed056ddb71c7a (patch)
tree812db6a9c2e9d78405ec0ed38465fd88dc5be748 /firmware/common
parent9b9bd73dfb212d4192fccc5fc5e269fc6499139c (diff)
downloadrockbox-d1322b71595336740eb5e18e5deed056ddb71c7a.tar.gz
rockbox-d1322b71595336740eb5e18e5deed056ddb71c7a.zip
GSoC/Buflib: Replace all direct accesses to audiobuf with buffer API functions.
Namely, introduce buffer_get_buffer() and buffer_release_buffer(). buffer_get_buffer() aquires all available and grabs a lock, attempting to call buffer_alloc() or buffer_get_buffer() while this lock is locked will cause a panicf() (doesn't actually happen, but is for debugging purpose). buffer_release_buffer() unlocks that lock and can additionally increment the audiobuf buffer to make an allocation. Pass 0 to only unlock if buffer was used temporarily only. buffer_available() is a replacement function to query audiobuflen, i.e. what's left in the buffer. Buffer init is moved up in the init chain and handles ipodvideo64mb internally. Further changes happened to mp3data.c and talk.c as to not call the above API functions, but get the buffer from callers. The caller is the audio system which has the buffer lock while mp3data.c and talk mess with the buffer. mpeg.c now implements some buffer related functions of playback.h, especially audio_get_buffer(), allowing to reduce #ifdef hell a tiny bit. audiobuf and audiobufend are local to buffer.c now. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30308 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/dircache.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 08fe5098f5..d114a6ac62 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -862,22 +862,26 @@ int dircache_build(int last_size)
862 * and their corresponding d_name from the end 862 * and their corresponding d_name from the end
863 * after generation the buffer will be compacted with DIRCACHE_RESERVE 863 * after generation the buffer will be compacted with DIRCACHE_RESERVE
864 * free bytes inbetween */ 864 * free bytes inbetween */
865 audiobuf = ALIGN_UP(audiobuf, sizeof(struct dircache_entry)); 865 size_t got_size;
866 dircache_root = (struct dircache_entry*)audiobuf; 866 char* buf = buffer_get_buffer(&got_size);
867 d_names_start = d_names_end = audiobufend - 1; 867 ALIGN_BUFFER(buf, got_size, sizeof(struct dircache_entry));
868 d_names_start = d_names_end = (char*)dircache_root + got_size - 1;
868 dircache_size = 0; 869 dircache_size = 0;
869 generate_dot_d_names(); 870 generate_dot_d_names();
870 871
871 /* Start a non-transparent rebuild. */ 872 /* Start a non-transparent rebuild. */
872 int res = dircache_do_rebuild(); 873 int res = dircache_do_rebuild();
873 if (res < 0) 874 if (res < 0)
874 return res; 875 goto fail;
875 876
876 /* now compact the dircache buffer */ 877 /* now compact the dircache buffer */
877 char* dst = ((char*)&dircache_root[entry_count] + DIRCACHE_RESERVE); 878 char* dst = ((char*)&dircache_root[entry_count] + DIRCACHE_RESERVE);
878 ptrdiff_t offset = d_names_start - dst; 879 ptrdiff_t offset = d_names_start - dst;
879 if (offset <= 0) /* something went wrong */ 880 if (offset <= 0) /* something went wrong */
880 return -1; 881 {
882 res = -1;
883 goto fail;
884 }
881 885
882 /* memmove d_names down, there's a possibility of overlap 886 /* memmove d_names down, there's a possibility of overlap
883 * equivaent to dircache_size - entry_count*sizeof(struct dircache_entry) */ 887 * equivaent to dircache_size - entry_count*sizeof(struct dircache_entry) */
@@ -896,15 +900,19 @@ int dircache_build(int last_size)
896 /* equivalent to dircache_size + DIRCACHE_RESERVE */ 900 /* equivalent to dircache_size + DIRCACHE_RESERVE */
897 allocated_size = (d_names_end - (char*)dircache_root); 901 allocated_size = (d_names_end - (char*)dircache_root);
898 reserve_used = 0; 902 reserve_used = 0;
899 audiobuf += allocated_size;
900 903
904 buffer_release_buffer(allocated_size);
905 return res;
906fail:
907 dircache_disable();
908 buffer_release_buffer(0);
901 return res; 909 return res;
902} 910}
903 911
904/** 912/**
905 * Steal the allocated dircache buffer and disable dircache. 913 * Steal the allocated dircache buffer and disable dircache.
906 */ 914 */
907void* dircache_steal_buffer(long *size) 915void* dircache_steal_buffer(size_t *size)
908{ 916{
909 dircache_disable(); 917 dircache_disable();
910 if (dircache_size == 0) 918 if (dircache_size == 0)