Index: ../apps/buffering.c =================================================================== --- ../apps/buffering.c (revision 17971) +++ ../apps/buffering.c (working copy) @@ -813,19 +813,26 @@ Return whether or not to continue filling after this */ static bool fill_buffer(void) { + struct memory_handle *m; logf("fill_buffer()"); - struct memory_handle *m = first_handle; - shrink_handle(m); + shrink_handle(first_handle); + mutex_lock(&llist_mutex); + m = first_handle; while (queue_empty(&buffering_queue) && m) { if (m->filerem > 0) { + mutex_unlock(&llist_mutex); if (!buffer_handle(m->id)) { m = NULL; break; } + mutex_lock(&llist_mutex); + m = first_handle; } m = m->next; } + mutex_unlock(&llist_mutex); + if (m) { return true; } @@ -924,10 +931,12 @@ if (adjusted_offset > size) adjusted_offset = 0; + mutex_lock(&llist_mutex); struct memory_handle *h = add_handle(size-adjusted_offset, can_wrap, false); if (!h) { DEBUGF("bufopen: failed to add handle\n"); + mutex_unlock(&llist_mutex); close(fd); return ERR_BUFFER_FULL; } @@ -943,7 +952,6 @@ { /* Bitmap file: we load the data instead of the file */ int rc; - mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */ rc = load_bitmap(fd); if (rc <= 0) { @@ -957,7 +965,6 @@ h->available = rc; h->widx = buf_widx + rc; /* safe because the data doesn't wrap */ buf_widx += rc; /* safe too */ - mutex_unlock(&llist_mutex); } else #endif @@ -968,6 +975,8 @@ h->widx = buf_widx; } + mutex_unlock(&llist_mutex); + if (type == TYPE_CUESHEET) { h->fd = fd; /* Immediately start buffering those */ @@ -1319,7 +1328,9 @@ static void shrink_buffer(void) { logf("shrink_buffer()"); + mutex_lock(&llist_mutex); shrink_buffer_inner(first_handle); + mutex_unlock(&llist_mutex); } void buffering_thread(void)