* coop.c (coop_condition_variable_wait): Removed
authorMikael Djurfeldt <djurfeldt@nada.kth.se>
Thu, 19 Nov 1998 08:15:22 +0000 (08:15 +0000)
committerMikael Djurfeldt <djurfeldt@nada.kth.se>
Thu, 19 Nov 1998 08:15:22 +0000 (08:15 +0000)
(coop_condition_variable_wait_mutex): Folded logic of
coop_mutex_unlock into coop_condition_variable_wait_mutex to
prevent condvar signal lossage.  Previously, another thread could
start to run after unlocking the mutex but before putting the
current thread on the wait queue.  If that thread then would
signal the first, the signal would be lost.  (Thanks to Christian
Lynbech.)

THANKS
libguile/ChangeLog
libguile/coop.c

diff --git a/THANKS b/THANKS
index 6737f33..5fa4680 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -4,6 +4,7 @@ Bug reports and fixes from:
 
      Etienne Bernard
         Brad Bowman
+        Ian Grant
    Christian Lynbech
         Russ McManus
      Nicolas Neuss
index 9d2922c..96bd81c 100644 (file)
@@ -1,3 +1,17 @@
+1998-11-19  Mikael Djurfeldt  <mdj@mdj.nada.kth.se>
+
+       * readline.c (scm_init_readline): Set
+       rl_basic_word_break_characters.  (Thanks to Ian Grant.)
+
+       * coop.c (coop_condition_variable_wait): Removed
+       (coop_condition_variable_wait_mutex): Folded logic of
+       coop_mutex_unlock into coop_condition_variable_wait_mutex to
+       prevent condvar signal lossage.  Previously, another thread could
+       start to run after unlocking the mutex but before putting the
+       current thread on the wait queue.  If that thread then would
+       signal the first, the signal would be lost.  (Thanks to Christian
+       Lynbech.)
+
 1998-11-17  Mikael Djurfeldt  <mdj@mdj.nada.kth.se>
 
        * eval.c (SCM_CEVAL): Added missing case for cclo.  (Thanks to
index d69f321..832df6e 100644 (file)
@@ -40,7 +40,7 @@
  * If you do not wish that, delete this exception notice.  */
 \f
 
-/* $Id: coop.c,v 1.14 1998-10-13 23:17:09 jimb Exp $ */
+/* $Id: coop.c,v 1.15 1998-11-19 08:15:22 mdj Exp $ */
 
 /* Cooperative thread library, based on QuickThreads */
 
@@ -333,6 +333,8 @@ coop_mutex_unlock (m)
 
       old = coop_global_curr;
       coop_global_curr = newthread;
+      /* The new thread came into m->waiting through a lock operation.
+        It now owns this mutex. */
       m->owner = coop_global_curr;
       QT_BLOCK (coop_yieldhelp, old, &coop_global_runq, newthread->sp);
     }
@@ -371,42 +373,39 @@ coop_condition_variable_init (c)
 }
 
 #ifdef __STDC__
-static int 
-coop_condition_variable_wait (coop_c *c)
+int 
+coop_condition_variable_wait_mutex (coop_c *c, coop_m *m)
 #else
-static int 
-coop_condition_variable_wait (c)
+int 
+coop_condition_variable_wait_mutex (c, m)
      coop_c *c;
+     coop_m *m;
 #endif
 {
   coop_t *old, *newthread;
 
+  /* coop_mutex_unlock (m); */
+  newthread = coop_qget (&(m->waiting));
+  if (newthread != NULL)
+    {
+      m->owner = newthread;
+    }
+  else
+    {
+      m->owner = NULL;
 #ifdef GUILE_ISELECT
-  newthread = coop_wait_for_runnable_thread();
-  if (newthread == coop_global_curr)
-    coop_abort ();
+      newthread = coop_wait_for_runnable_thread();
+      if (newthread == coop_global_curr)
+       coop_abort ();
 #else
-  newthread = coop_next_runnable_thread();
+      newthread = coop_next_runnable_thread();
 #endif
+    }
+  coop_global_curr->top = &old;
   old = coop_global_curr;
   coop_global_curr = newthread;
   QT_BLOCK (coop_yieldhelp, old, &(c->waiting), newthread->sp);
-  return 0;
-}
-
 
-#ifdef __STDC__
-int 
-coop_condition_variable_wait_mutex (coop_c *c, coop_m *m)
-#else
-int 
-coop_condition_variable_wait_mutex (c, m)
-     coop_c *c;
-     coop_m *m;
-#endif
-{
-  coop_mutex_unlock (m);
-  coop_condition_variable_wait (c);
   coop_mutex_lock (m);
   return 0;
 }