diff -r cc5e9ec110a4 -r f2590691d4b7 src/neon/neon.c
--- a/src/neon/neon.c Thu Nov 22 02:54:06 2007 +0300
+++ b/src/neon/neon.c Thu Nov 22 15:52:42 2007 +0100
@@ -885,7 +885,8 @@ size_t neon_aud_vfs_fread_impl(gpointer
* We have to check if the reader terminated gracefully
* again
*/
- if (NEON_READER_TERM != h->reader_status.status) {
+ if ((NEON_READER_TERM != h->reader_status.status) &&
+ (NEON_READER_EOF != h->reader_status.status)) {
/*
* Reader thread did not terminate gracefully.
*/
@@ -918,13 +919,14 @@ size_t neon_aud_vfs_fread_impl(gpointer
* We have some data in the buffer now.
* Start the reader thread.
*/
+ g_mutex_lock(h->reader_status.mutex);
h->reader_status.reading = TRUE;
if (NULL == (h->reader = g_thread_create(reader_thread, h, TRUE, NULL))) {
h->reader_status.reading = FALSE;
+ g_mutex_unlock(h->reader_status.mutex);
_ERROR("Error creating reader thread!");
_LEAVE 0;
}
- g_mutex_lock(h->reader_status.mutex);
h->reader_status.status = NEON_READER_RUN;
g_mutex_unlock(h->reader_status.mutex);
} else {
@@ -946,7 +948,7 @@ size_t neon_aud_vfs_fread_impl(gpointer
* If there still is data in the buffer, carry on.
* If not, terminate the reader thread and return 0.
*/
- if (0 == used_rb(&h->rb)) {
+ if (0 == used_rb_locked(&h->rb)) {
_DEBUG("Reached end of stream");
g_mutex_unlock(h->reader_status.mutex);
kill_reader(h);
diff -r cc5e9ec110a4 -r f2590691d4b7 src/neon/rb.c
--- a/src/neon/rb.c Thu Nov 22 02:54:06 2007 +0300
+++ b/src/neon/rb.c Thu Nov 22 15:52:42 2007 +0100
@@ -343,10 +343,21 @@ unsigned int used_rb(struct ringbuf* rb)
_ENTER;
_RB_LOCK(rb->lock);
- u = rb->used;
+ u = used_rb_locked(rb);
_RB_UNLOCK(rb->lock);
_LEAVE u;
+}
+
+/*
+ * Return the amount of used space currently in the rb.
+ * Assume the rb lock is already being held.
+ */
+unsigned int used_rb_locked(struct ringbuf* rb) {
+
+ _ENTER;
+
+ _LEAVE rb->used;
}
diff -r cc5e9ec110a4 -r f2590691d4b7 src/neon/rb.h
--- a/src/neon/rb.h Thu Nov 22 02:54:06 2007 +0300
+++ b/src/neon/rb.h Thu Nov 22 15:52:42 2007 +0100
@@ -61,6 +61,7 @@ unsigned int free_rb(struct ringbuf* rb)
unsigned int free_rb(struct ringbuf* rb);
unsigned int free_rb_locked(struct ringbuf* rb);
unsigned int used_rb(struct ringbuf* rb);
+unsigned int used_rb_locked(struct ringbuf* rb);
void destroy_rb(struct ringbuf* rb);
#endif