Add 'want_to_read' to GStaticRWLock to avoid calling g_cond_broadcast,
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>
Thu, 30 Aug 2001 14:19:20 +0000 (14:19 +0000)
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>
Thu, 30 Aug 2001 14:19:20 +0000 (14:19 +0000)
2001-08-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

* glib/gthread.h, glib/gthread.c: Add 'want_to_read' to
GStaticRWLock to avoid calling g_cond_broadcast, when no one is
waiting.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gthread.c
glib/gthread.h

index 78fe193..b6af46b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2001-08-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * glib/gthread.h, glib/gthread.c: Add 'want_to_read' to
+       GStaticRWLock to avoid calling g_cond_broadcast, when no one is
+       waiting.
+
        * glib/gmain.c (g_main_context_add_poll_unlocked): Don't free
        cached_poll_array, when adding new poll's. This is taken care for
        in g_main_context_iterate.
index 78fe193..b6af46b 100644 (file)
@@ -1,5 +1,9 @@
 2001-08-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * glib/gthread.h, glib/gthread.c: Add 'want_to_read' to
+       GStaticRWLock to avoid calling g_cond_broadcast, when no one is
+       waiting.
+
        * glib/gmain.c (g_main_context_add_poll_unlocked): Don't free
        cached_poll_array, when adding new poll's. This is taken care for
        in g_main_context_iterate.
index 78fe193..b6af46b 100644 (file)
@@ -1,5 +1,9 @@
 2001-08-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * glib/gthread.h, glib/gthread.c: Add 'want_to_read' to
+       GStaticRWLock to avoid calling g_cond_broadcast, when no one is
+       waiting.
+
        * glib/gmain.c (g_main_context_add_poll_unlocked): Don't free
        cached_poll_array, when adding new poll's. This is taken care for
        in g_main_context_iterate.
index 78fe193..b6af46b 100644 (file)
@@ -1,5 +1,9 @@
 2001-08-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * glib/gthread.h, glib/gthread.c: Add 'want_to_read' to
+       GStaticRWLock to avoid calling g_cond_broadcast, when no one is
+       waiting.
+
        * glib/gmain.c (g_main_context_add_poll_unlocked): Don't free
        cached_poll_array, when adding new poll's. This is taken care for
        in g_main_context_iterate.
index 78fe193..b6af46b 100644 (file)
@@ -1,5 +1,9 @@
 2001-08-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * glib/gthread.h, glib/gthread.c: Add 'want_to_read' to
+       GStaticRWLock to avoid calling g_cond_broadcast, when no one is
+       waiting.
+
        * glib/gmain.c (g_main_context_add_poll_unlocked): Don't free
        cached_poll_array, when adding new poll's. This is taken care for
        in g_main_context_iterate.
index 78fe193..b6af46b 100644 (file)
@@ -1,5 +1,9 @@
 2001-08-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * glib/gthread.h, glib/gthread.c: Add 'want_to_read' to
+       GStaticRWLock to avoid calling g_cond_broadcast, when no one is
+       waiting.
+
        * glib/gmain.c (g_main_context_add_poll_unlocked): Don't free
        cached_poll_array, when adding new poll's. This is taken care for
        in g_main_context_iterate.
index 78fe193..b6af46b 100644 (file)
@@ -1,5 +1,9 @@
 2001-08-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * glib/gthread.h, glib/gthread.c: Add 'want_to_read' to
+       GStaticRWLock to avoid calling g_cond_broadcast, when no one is
+       waiting.
+
        * glib/gmain.c (g_main_context_add_poll_unlocked): Don't free
        cached_poll_array, when adding new poll's. This is taken care for
        in g_main_context_iterate.
index 78fe193..b6af46b 100644 (file)
@@ -1,5 +1,9 @@
 2001-08-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * glib/gthread.h, glib/gthread.c: Add 'want_to_read' to
+       GStaticRWLock to avoid calling g_cond_broadcast, when no one is
+       waiting.
+
        * glib/gmain.c (g_main_context_add_poll_unlocked): Don't free
        cached_poll_array, when adding new poll's. This is taken care for
        in g_main_context_iterate.
index ea16bcd..96cb3f4 100644 (file)
@@ -692,7 +692,7 @@ g_static_rw_lock_signal (GStaticRWLock* lock)
 {
   if (lock->want_to_write && lock->write_cond)
     g_cond_signal (lock->write_cond);
-  else if (lock->read_cond)
+  else if (lock->want_to_read && lock->read_cond)
     g_cond_broadcast (lock->read_cond);
 }
 
@@ -705,8 +705,10 @@ g_static_rw_lock_reader_lock (GStaticRWLock* lock)
     return;
 
   g_static_mutex_lock (&lock->mutex);
+  lock->want_to_read++;
   while (lock->write || lock->want_to_write) 
     g_static_rw_lock_wait (&lock->read_cond, &lock->mutex);
+  lock->want_to_read--;
   lock->read_counter++;
   g_static_mutex_unlock (&lock->mutex);
 }
index 58043bf..215cc28 100644 (file)
@@ -263,10 +263,11 @@ struct _GStaticRWLock
   GCond *write_cond;
   guint read_counter;
   gboolean write;
+  guint want_to_read;
   guint want_to_write;
 };
 
-#define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, FALSE }
+#define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, 0, 0 }
 
 void      g_static_rw_lock_init           (GStaticRWLock* lock);
 void      g_static_rw_lock_reader_lock    (GStaticRWLock* lock);