[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 11/17: Mutex instead of critical section in gc.c
From: |
Andy Wingo |
Subject: |
[Guile-commits] 11/17: Mutex instead of critical section in gc.c |
Date: |
Tue, 1 Nov 2016 22:50:44 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit 42882bbf42fa70a3c7174909a32a91b9ff68abbf
Author: Andy Wingo <address@hidden>
Date: Tue Nov 1 22:57:54 2016 +0100
Mutex instead of critical section in gc.c
* libguile/gc.c (scm_gc_protect_object, scm_gc_unprotect_object): Use a
mutex instead of a critical section. Remove dead code.
---
libguile/gc.c | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
diff --git a/libguile/gc.c b/libguile/gc.c
index 1e9f596..6044753 100644
--- a/libguile/gc.c
+++ b/libguile/gc.c
@@ -496,22 +496,21 @@ scm_permanent_object (SCM obj)
+static scm_i_pthread_mutex_t gc_protect_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
+
SCM
scm_gc_protect_object (SCM obj)
{
SCM handle;
- /* This critical section barrier will be replaced by a mutex. */
- /* njrev: Indeed; if my comment above is correct, there is the same
- critsec/mutex inconsistency here. */
- SCM_CRITICAL_SECTION_START;
+ scm_dynwind_begin (0);
+ scm_dynwind_pthread_mutex_lock (&gc_protect_lock);
handle = scm_hashq_create_handle_x (scm_protects, obj, scm_from_int (0));
SCM_SETCDR (handle, scm_sum (SCM_CDR (handle), scm_from_int (1)));
-
protected_obj_count ++;
-
- SCM_CRITICAL_SECTION_END;
+
+ scm_dynwind_end ();
return obj;
}
@@ -526,18 +525,10 @@ scm_gc_unprotect_object (SCM obj)
{
SCM handle;
- /* This critical section barrier will be replaced by a mutex. */
- /* njrev: and again. */
- SCM_CRITICAL_SECTION_START;
+ scm_dynwind_begin (0);
+ scm_dynwind_pthread_mutex_lock (&gc_protect_lock);
- if (scm_gc_running_p)
- {
- fprintf (stderr, "scm_unprotect_object called during GC.\n");
- abort ();
- }
-
handle = scm_hashq_get_handle (scm_protects, obj);
-
if (scm_is_false (handle))
{
fprintf (stderr, "scm_unprotect_object called on unprotected object\n");
@@ -553,7 +544,7 @@ scm_gc_unprotect_object (SCM obj)
}
protected_obj_count --;
- SCM_CRITICAL_SECTION_END;
+ scm_dynwind_end ();
return obj;
}
- [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 <=
- [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, 2016/11/01
- [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