summaryrefslogtreecommitdiffstats
path: root/apps/buffering.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-02-13 10:44:13 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-02-13 10:44:13 +0000
commitb474d0d98fd53353f2680d73b91b45184106a39c (patch)
treee1debb1da2ef1dcc02bdc177daa1dcfbf72b5322 /apps/buffering.c
parente8e0ca2c573189d14a98c4644aeac0b02a7b12a8 (diff)
downloadrockbox-b474d0d98fd53353f2680d73b91b45184106a39c.tar.gz
rockbox-b474d0d98fd53353f2680d73b91b45184106a39c.tar.bz2
rockbox-b474d0d98fd53353f2680d73b91b45184106a39c.zip
Change add_handle to never have side effects on the buffer if it fails. It actually seems ok and I'm not sure if's responsible for anything, but it's more sane and keeps buffer_handle from regressing buf_widx later if buffering cur_handle.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29291 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 48ef1bc6c0..213826fda0 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -243,10 +243,7 @@ buf_ridx == buf_widx means the buffer is empty.
alloc_all tells us if we must immediately be able to allocate data_size
returns a valid memory handle if all conditions for allocation are met.
NULL if there memory_handle itself cannot be allocated or if the
- data_size cannot be allocated and alloc_all is set. This function's
- only potential side effect is to allocate space for the cur_handle
- if it returns NULL.
- */
+ data_size cannot be allocated and alloc_all is set. */
static struct memory_handle *add_handle(size_t data_size, bool can_wrap,
bool alloc_all)
{
@@ -263,6 +260,8 @@ static struct memory_handle *add_handle(size_t data_size, bool can_wrap,
mutex_lock(&llist_mutex);
mutex_lock(&llist_mod_mutex);
+ new_widx = buf_widx;
+
if (cur_handle && cur_handle->filerem > 0) {
/* the current handle hasn't finished buffering. We can only add
a new one if there is already enough free space to finish
@@ -275,12 +274,12 @@ static struct memory_handle *add_handle(size_t data_size, bool can_wrap,
return NULL;
} else {
/* Allocate the remainder of the space for the current handle */
- buf_widx = ringbuf_add(cur_handle->widx, cur_handle->filerem);
+ new_widx = ringbuf_add(cur_handle->widx, cur_handle->filerem);
}
}
/* align to 4 bytes up */
- new_widx = ringbuf_add(buf_widx, 3) & ~3;
+ new_widx = ringbuf_add(new_widx, 3) & ~3;
len = data_size + sizeof(struct memory_handle);