summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-11-01 22:57:54 +0100
committerAndy Wingo <wingo@pobox.com>2016-11-01 22:57:54 +0100
commit42882bbf42fa70a3c7174909a32a91b9ff68abbf (patch)
tree94d528d86d12c2937fec9ccb50c77f4c2fc64095
parente7e7a719bace8b71b351b9305940a7b4a724cc81 (diff)
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.
-rw-r--r--libguile/gc.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/libguile/gc.c b/libguile/gc.c
index 1e9f59683..6044753ce 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;
}