guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 03/17: threads: Use a mutex instead of a critical sectio


From: Andy Wingo
Subject: [Guile-commits] 03/17: threads: Use a mutex instead of a critical section.
Date: Tue, 1 Nov 2016 22:50:44 +0000 (UTC)

wingo pushed a commit to branch master
in repository guile.

commit 0a663877acb5ab5b79d7fafa5075d1f535527942
Author: Andy Wingo <address@hidden>
Date:   Tue Nov 1 21:26:42 2016 +0100

    threads: Use a mutex instead of a critical section.
    
    * libguile/threads.c: Replace uses of critical sections with a dedicated
      mutex.
---
 libguile/threads.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/libguile/threads.c b/libguile/threads.c
index 37381cb..b2b3528 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -159,6 +159,8 @@ make_queue ()
   return scm_cons (SCM_EOL, SCM_EOL);
 }
 
+static scm_i_pthread_mutex_t queue_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
+
 /* Put T at the back of Q and return a handle that can be used with
    remqueue to remove T from Q again.
  */
@@ -166,13 +168,13 @@ static SCM
 enqueue (SCM q, SCM t)
 {
   SCM c = scm_cons (t, SCM_EOL);
-  SCM_CRITICAL_SECTION_START;
+  scm_i_pthread_mutex_lock (&queue_lock);
   if (scm_is_null (SCM_CDR (q)))
     SCM_SETCDR (q, c);
   else
     SCM_SETCDR (SCM_CAR (q), c);
   SCM_SETCAR (q, c);
-  SCM_CRITICAL_SECTION_END;
+  scm_i_pthread_mutex_unlock (&queue_lock);
   return c;
 }
 
@@ -185,7 +187,7 @@ static int
 remqueue (SCM q, SCM c)
 {
   SCM p, prev = q;
-  SCM_CRITICAL_SECTION_START;
+  scm_i_pthread_mutex_lock (&queue_lock);
   for (p = SCM_CDR (q); !scm_is_null (p); p = SCM_CDR (p))
     {
       if (scm_is_eq (p, c))
@@ -197,12 +199,12 @@ remqueue (SCM q, SCM c)
          /* GC-robust */
          SCM_SETCDR (c, SCM_EOL);
 
-         SCM_CRITICAL_SECTION_END;
+          scm_i_pthread_mutex_unlock (&queue_lock);
          return 1;
        }
       prev = p;
     }
-  SCM_CRITICAL_SECTION_END;
+  scm_i_pthread_mutex_unlock (&queue_lock);
   return 0;
 }
 
@@ -213,11 +215,11 @@ static SCM
 dequeue (SCM q)
 {
   SCM c;
-  SCM_CRITICAL_SECTION_START;
+  scm_i_pthread_mutex_lock (&queue_lock);
   c = SCM_CDR (q);
   if (scm_is_null (c))
     {
-      SCM_CRITICAL_SECTION_END;
+      scm_i_pthread_mutex_unlock (&queue_lock);
       return SCM_BOOL_F;
     }
   else
@@ -225,7 +227,7 @@ dequeue (SCM q)
       SCM_SETCDR (q, SCM_CDR (c));
       if (scm_is_null (SCM_CDR (q)))
        SCM_SETCAR (q, SCM_EOL);
-      SCM_CRITICAL_SECTION_END;
+      scm_i_pthread_mutex_unlock (&queue_lock);
 
       /* GC-robust */
       SCM_SETCDR (c, SCM_EOL);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]