From d1322b71595336740eb5e18e5deed056ddb71c7a Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sun, 14 Aug 2011 15:13:00 +0000 Subject: 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 --- firmware/common/dircache.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'firmware/common') 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) * and their corresponding d_name from the end * after generation the buffer will be compacted with DIRCACHE_RESERVE * free bytes inbetween */ - audiobuf = ALIGN_UP(audiobuf, sizeof(struct dircache_entry)); - dircache_root = (struct dircache_entry*)audiobuf; - d_names_start = d_names_end = audiobufend - 1; + size_t got_size; + char* buf = buffer_get_buffer(&got_size); + ALIGN_BUFFER(buf, got_size, sizeof(struct dircache_entry)); + d_names_start = d_names_end = (char*)dircache_root + got_size - 1; dircache_size = 0; generate_dot_d_names(); /* Start a non-transparent rebuild. */ int res = dircache_do_rebuild(); if (res < 0) - return res; + goto fail; /* now compact the dircache buffer */ char* dst = ((char*)&dircache_root[entry_count] + DIRCACHE_RESERVE); ptrdiff_t offset = d_names_start - dst; if (offset <= 0) /* something went wrong */ - return -1; + { + res = -1; + goto fail; + } /* memmove d_names down, there's a possibility of overlap * equivaent to dircache_size - entry_count*sizeof(struct dircache_entry) */ @@ -896,15 +900,19 @@ int dircache_build(int last_size) /* equivalent to dircache_size + DIRCACHE_RESERVE */ allocated_size = (d_names_end - (char*)dircache_root); reserve_used = 0; - audiobuf += allocated_size; + buffer_release_buffer(allocated_size); + return res; +fail: + dircache_disable(); + buffer_release_buffer(0); return res; } /** * Steal the allocated dircache buffer and disable dircache. */ -void* dircache_steal_buffer(long *size) +void* dircache_steal_buffer(size_t *size) { dircache_disable(); if (dircache_size == 0) -- cgit v1.2.3