Use ringbuf_add in buffering when incrementing for initial allocation of non-wrapping data. The result of the shortcut would have been wrong if the handle used space exactly to the end of the buffer since buf_widx wouldn't have been properly wrapped to index 0.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29578 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2011-03-13 11:56:51 +00:00
parent e86a7fb77d
commit 7cac18f94b

View file

@ -950,8 +950,8 @@ int bufopen(const char *file, size_t offset, enum data_type type,
h->type = type; h->type = type;
strlcpy(h->path, file, MAX_PATH); strlcpy(h->path, file, MAX_PATH);
buf_widx += sizeof(struct mp3entry); /* safe because the handle buf_widx = ringbuf_add(buf_widx, sizeof(struct mp3entry));
can't wrap */
h->filerem = sizeof(struct mp3entry); h->filerem = sizeof(struct mp3entry);
/* Inform the buffering thread that we added a handle */ /* Inform the buffering thread that we added a handle */
@ -1037,8 +1037,8 @@ int bufopen(const char *file, size_t offset, enum data_type type,
} else { } else {
h->filesize = rc; h->filesize = rc;
h->available = rc; h->available = rc;
h->widx = buf_widx + rc; /* safe because the data doesn't wrap */ buf_widx = ringbuf_add(buf_widx, rc);
buf_widx += rc; /* safe too */ h->widx = buf_widx;
} }
} }
else else
@ -1107,12 +1107,11 @@ int bufalloc(const void *src, size_t size, enum data_type type)
h->filesize = size; h->filesize = size;
h->offset = 0; h->offset = 0;
h->ridx = buf_widx; h->ridx = buf_widx;
h->widx = buf_widx + size; /* safe because the data doesn't wrap */
h->data = buf_widx; h->data = buf_widx;
buf_widx = ringbuf_add(buf_widx, size);
h->widx = buf_widx;
h->available = size; h->available = size;
h->type = type; h->type = type;
buf_widx += size; /* safe too */
} }
mutex_unlock(&llist_mutex); mutex_unlock(&llist_mutex);