summaryrefslogtreecommitdiff
path: root/libguile/threads.c
diff options
context:
space:
mode:
Diffstat (limited to 'libguile/threads.c')
-rw-r--r--libguile/threads.c61
1 files changed, 25 insertions, 36 deletions
diff --git a/libguile/threads.c b/libguile/threads.c
index 380864f6f..8dbd75982 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -40,7 +40,6 @@
#endif
#include "async.h"
-#include "bdw-gc.h"
#include "boolean.h"
#include "continuations.h"
#include "deprecation.h"
@@ -72,8 +71,6 @@
#include "threads.h"
-#include <gc/gc_mark.h>
-
@@ -612,20 +609,12 @@ scm_init_guile (void)
struct with_guile_args
{
- GC_fn_type func;
+ void* (*func) (void*);
void *data;
SCM dynamic_state;
};
static void *
-with_guile_trampoline (void *data)
-{
- struct with_guile_args *args = data;
-
- return scm_c_with_continuation_barrier (args->func, args->data);
-}
-
-static void *
with_guile (struct gc_stack_addr base, void *data)
{
void *res;
@@ -635,22 +624,10 @@ with_guile (struct gc_stack_addr base, void *data)
new_thread = scm_i_init_thread_for_guile (base, args->dynamic_state);
t = SCM_I_CURRENT_THREAD;
- if (new_thread)
- {
- /* We are in Guile mode. */
- assert (t->guile_mode);
-
- res = scm_c_with_continuation_barrier (args->func, args->data);
+ int reactivate = !t->guile_mode;
+ int deactivate = reactivate || new_thread;
- /* Leave Guile mode. */
- t->guile_mode = 0;
- }
- else if (t->guile_mode)
- {
- /* Already in Guile mode. */
- res = scm_c_with_continuation_barrier (args->func, args->data);
- }
- else
+ if (reactivate)
{
/* We are not in Guile mode, either because we are not within a
scm_with_guile, or because we are within a scm_without_guile.
@@ -668,9 +645,17 @@ with_guile (struct gc_stack_addr base, void *data)
#endif
t->guile_mode = 1;
- res = GC_call_with_gc_active (with_guile_trampoline, args);
+ gc_reactivate (t->mutator);
+ }
+
+ res = scm_c_with_continuation_barrier (args->func, args->data);
+
+ if (deactivate)
+ {
+ gc_deactivate (t->mutator);
t->guile_mode = 0;
}
+
return res;
}
@@ -697,16 +682,21 @@ scm_without_guile (void *(*func)(void *), void *data)
{
void *result;
scm_thread *t = SCM_I_CURRENT_THREAD;
+ int was_active = t->guile_mode;
- if (t->guile_mode)
+ if (was_active)
{
- SCM_I_CURRENT_THREAD->guile_mode = 0;
- result = GC_do_blocking (func, data);
- SCM_I_CURRENT_THREAD->guile_mode = 1;
+ t->guile_mode = 0;
+ gc_deactivate (t->mutator);
+ }
+
+ result = func (data);
+
+ if (was_active)
+ {
+ gc_reactivate (t->mutator);
+ t->guile_mode = 1;
}
- else
- /* Otherwise we're not in guile mode, so nothing to do. */
- result = func (data);
return result;
}
@@ -797,7 +787,6 @@ SCM_DEFINE (scm_sys_call_with_new_thread, "%call-with-new-thread", 1, 0, 0,
SCM_ASSERT (scm_is_true (scm_thunk_p (thunk)), thunk, SCM_ARG1, FUNC_NAME);
- GC_collect_a_little ();
data = scm_gc_typed_calloc (launch_data);
data->dynamic_state = scm_current_dynamic_state ();
data->thunk = thunk;