changeset 2184:f2590691d4b7

- Fix locking issues causing spurious error messages (and possibly deadlocks)
author Ralf Ertzinger <ralf@skytale.net>
date Thu, 22 Nov 2007 15:52:42 +0100
parents b73ea297d197
children 145966acb0c4
files src/neon/neon.c
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/neon/neon.c	Thu Nov 22 15:51:52 2007 +0100
+++ b/src/neon/neon.c	Thu Nov 22 15:52:42 2007 +0100
@@ -885,7 +885,8 @@
              * 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 @@
          * 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 @@
                  * 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);