Index: apps/playback.c =================================================================== --- apps/playback.c (revisione 23221) +++ apps/playback.c (copia locale) @@ -2468,6 +2468,9 @@ */ static void audio_reset_buffer(void) { + /* prevent any further use of buffer_alloc */ + buffer_lock(); + /* see audio_get_recording_buffer if this is modified */ logf("audio_reset_buffer"); @@ -2741,8 +2744,8 @@ pcmbuf_crossfade_enable(global_settings.crossfade); /* initialize the buffering system */ + buffering_init(); - buffering_init(); /* ...now! Set up the buffers */ audio_reset_buffer(); Index: firmware/export/buffer.h =================================================================== --- firmware/export/buffer.h (revisione 23221) +++ firmware/export/buffer.h (copia locale) @@ -32,5 +32,6 @@ void buffer_init(void); void *buffer_alloc(size_t size); +void buffer_lock(void); #endif Index: firmware/common/dircache.c =================================================================== --- firmware/common/dircache.c (revisione 23221) +++ firmware/common/dircache.c (copia locale) @@ -550,7 +550,7 @@ /** * Internal function which scans the disk and creates the dircache structure. */ -static int dircache_do_rebuild(void) +static int dircache_do_rebuild(bool allowbufferalloc) { #ifdef SIMULATOR DIR_UNCACHED *pdir; @@ -628,7 +628,7 @@ dircache_bind(fdbind_cache[i].fd, fdbind_cache[i].path); fdbind_idx = 0; - if (thread_enabled) + if (!allowbufferalloc) { if (allocated_size - dircache_size < DIRCACHE_RESERVE) reserve_used = DIRCACHE_RESERVE - (allocated_size - dircache_size); @@ -636,9 +636,8 @@ else { /* We have to long align the audiobuf to keep the buffer access fast. */ - audiobuf += (long)((dircache_size & ~0x03) + 0x04); - audiobuf += DIRCACHE_RESERVE; allocated_size = dircache_size + DIRCACHE_RESERVE; + buffer_alloc(allocated_size); reserve_used = 0; } @@ -666,7 +665,7 @@ #endif case DIRCACHE_BUILD: thread_enabled = true; - dircache_do_rebuild(); + dircache_do_rebuild(false); thread_enabled = false; break ; @@ -717,10 +716,10 @@ return 3; } - dircache_root = (struct dircache_entry *)(((long)audiobuf & ~0x03) + 0x04); + dircache_root = (struct dircache_entry *) buffer_alloc(0); // /* Start a non-transparent rebuild. */ - return dircache_do_rebuild(); + return dircache_do_rebuild(true); } /** Index: firmware/buffer.c =================================================================== --- firmware/buffer.c (revisione 23221) +++ firmware/buffer.c (copia locale) @@ -20,6 +20,7 @@ ****************************************************************************/ #include #include "buffer.h" +#include "panic.h" #ifdef SIMULATOR unsigned char audiobuffer[(MEM*1024-256)*1024]; @@ -30,15 +31,20 @@ #endif unsigned char *audiobuf; +static int locked; void buffer_init(void) { /* 32-bit aligned */ audiobuf = (void *)(((unsigned long)audiobuffer + 3) & ~3); + locked = 0; } void *buffer_alloc(size_t size) { + if (locked != 0) + panicf("Attempt to resize audio buffer whilst in use. size=%lu", size); + void *retval = audiobuf; audiobuf += size; @@ -48,3 +54,7 @@ return retval; } +void buffer_lock(void) +{ + locked = 1; +}