1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-07 12:40:19 +02:00

Excise BDW API use from threads.c

* libguile/threads.c (with_guile, scm_without_guile): Use gc_activate /
gc_deactivate API.  It's a noop on BDW, but all we lose is a bit of
precision.
(%call-with-new-thread): Remove GC_collect_a_little call, it was
useless.
This commit is contained in:
Andy Wingo 2025-05-15 11:50:47 +02:00
parent 173adcfe09
commit 8b12d6f26c

View file

@ -40,7 +40,6 @@
#endif #endif
#include "async.h" #include "async.h"
#include "bdw-gc.h"
#include "boolean.h" #include "boolean.h"
#include "continuations.h" #include "continuations.h"
#include "deprecation.h" #include "deprecation.h"
@ -72,8 +71,6 @@
#include "threads.h" #include "threads.h"
#include <gc/gc_mark.h>
@ -612,19 +609,11 @@ scm_init_guile (void)
struct with_guile_args struct with_guile_args
{ {
GC_fn_type func; void* (*func) (void*);
void *data; void *data;
SCM dynamic_state; 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 * static void *
with_guile (struct gc_stack_addr base, void *data) with_guile (struct gc_stack_addr base, void *data)
{ {
@ -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); new_thread = scm_i_init_thread_for_guile (base, args->dynamic_state);
t = SCM_I_CURRENT_THREAD; t = SCM_I_CURRENT_THREAD;
if (new_thread) int reactivate = !t->guile_mode;
{ int deactivate = reactivate || new_thread;
/* We are in Guile mode. */
assert (t->guile_mode);
res = scm_c_with_continuation_barrier (args->func, args->data); if (reactivate)
/* 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
{ {
/* We are not in Guile mode, either because we are not within a /* 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. 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 #endif
t->guile_mode = 1; 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; t->guile_mode = 0;
} }
return res; return res;
} }
@ -697,16 +682,21 @@ scm_without_guile (void *(*func)(void *), void *data)
{ {
void *result; void *result;
scm_thread *t = SCM_I_CURRENT_THREAD; 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; t->guile_mode = 0;
result = GC_do_blocking (func, data); gc_deactivate (t->mutator);
SCM_I_CURRENT_THREAD->guile_mode = 1; }
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; 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); 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 = scm_gc_typed_calloc (launch_data);
data->dynamic_state = scm_current_dynamic_state (); data->dynamic_state = scm_current_dynamic_state ();
data->thunk = thunk; data->thunk = thunk;