[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);
- [Guile-commits] branch master updated (eeeee32 -> fcc6a7b), Andy Wingo, 2016/11/01
- [Guile-commits] 04/17: sigaction critical section refactor., Andy Wingo, 2016/11/01
- [Guile-commits] 06/17: Remove unused internal definitions, Andy Wingo, 2016/11/01
- [Guile-commits] 13/17: Mutex in dynamic linker, Andy Wingo, 2016/11/01
- [Guile-commits] 11/17: Mutex instead of critical section in gc.c, Andy Wingo, 2016/11/01
- [Guile-commits] 16/17: Threads no longer track critical section level, Andy Wingo, 2016/11/01
- [Guile-commits] 03/17: threads: Use a mutex instead of a critical section.,
Andy Wingo <=
- [Guile-commits] 07/17: Mutexes instead of critical sections in stime.c, Andy Wingo, 2016/11/01
- [Guile-commits] 01/17: api-scheduling.texi: Syntactic cleanups., Andy Wingo, 2016/11/01
- [Guile-commits] 08/17: Mutex instead of critical sectoin in symbol->keyword, Andy Wingo, 2016/11/01
- [Guile-commits] 05/17: regexec comment fix, Andy Wingo, 2016/11/01
- [Guile-commits] 15/17: Remove call/cc assertion about critical sections, Andy Wingo, 2016/11/01
- [Guile-commits] 09/17: Simplify critical section implementation, Andy Wingo, 2016/11/01
- [Guile-commits] 10/17: Mutex instead of critical section in GOOPS, Andy Wingo, 2016/11/01
- [Guile-commits] 02/17: Add scm_yield to manual alongside yield, Andy Wingo, 2016/11/01
- [Guile-commits] 12/17: Remove critical section in scm_debug_options, Andy Wingo, 2016/11/01
- [Guile-commits] 14/17: Remove last critical section use, Andy Wingo, 2016/11/01