process: use GC_thread_is_registered() instead of the_env->cleanup

This allows us to remove unnecessary bookkeeping.
This commit is contained in:
Daniel Kochmański 2024-05-03 08:40:50 +02:00
parent 0451796b51
commit 0846b149df
3 changed files with 24 additions and 28 deletions

View file

@ -170,7 +170,6 @@ _ecl_alloc_env(cl_env_ptr parent)
#if defined(ECL_THREADS)
output->bds_stack.tl_bindings_size = 0;
output->bds_stack.tl_bindings = NULL;
output->cleanup = 0;
#endif
output->own_process = ECL_NIL;
{

View file

@ -143,6 +143,28 @@ del_env(cl_env_ptr the_env)
ecl_mutex_unlock(&ecl_core.processes_lock);
}
static void
register_gc_thread()
{
#ifdef GBC_BOEHM
if (GC_thread_is_registered() == 0) {
struct GC_stack_base stack;
GC_get_stack_base(&stack);
GC_register_my_thread(&stack);
}
#endif
}
static void
unregister_gc_thread()
{
#ifdef GBC_BOEHM
if (GC_thread_is_registered() == 1) {
GC_unregister_my_thread();
}
#endif
}
/* Run a process in the current system thread. */
cl_env_ptr
ecl_adopt_cpu()
@ -151,28 +173,10 @@ ecl_adopt_cpu()
struct ecl_interrupt_struct int_aux[1];
cl_env_ptr the_env = ecl_process_env_unsafe();
ecl_thread_t current;
int registered;
if (the_env != NULL)
return the_env;
/* Ensure that the thread is known to the GC. */
/* FIXME this should be executed with hooks. */
#ifdef GBC_BOEHM
{
struct GC_stack_base stack;
GC_get_stack_base(&stack);
switch (GC_register_my_thread(&stack)) {
case GC_SUCCESS:
registered = 1;
break;
case GC_DUPLICATE:
/* Thread was probably created using the GC hooks for thread creation. */
registered = 0;
break;
default:
ecl_internal_error("gc returned an impossible answer.");
}
}
#endif
register_gc_thread();
ecl_set_process_self(current);
/* We need a fake env to allow for interrupts blocking and to set up frame
* stacks or other stuff that is needed by ecl_init_env. Since the fake env is
@ -186,7 +190,6 @@ ecl_adopt_cpu()
env_aux->interrupt_struct->signal_queue = ECL_NIL;
ecl_set_process_env(env_aux);
env_aux->thread = current;
env_aux->cleanup = registered;
ecl_init_env(env_aux);
/* Allocate, initialize and switch to the real environment. */
@ -202,11 +205,9 @@ ecl_adopt_cpu()
void
ecl_disown_cpu()
{
int registered;
cl_env_ptr the_env = ecl_process_env_unsafe();
if (the_env == NULL)
return;
registered = the_env->cleanup;
ecl_disable_interrupts_env(the_env);
/* FIXME this should be part of dealloc. */
ecl_clear_bignum_registers(the_env);
@ -216,10 +217,7 @@ ecl_disown_cpu()
ecl_set_process_env(NULL);
del_env(the_env);
_ecl_dealloc_env(the_env);
/* FIXME thsi should be executed with hooks. */
if (registered) {
GC_unregister_my_thread();
}
unregister_gc_thread();
}
#ifdef ECL_WINDOWS_THREADS

View file

@ -104,7 +104,6 @@ struct cl_env_struct {
cl_object own_process; /* Backpointer to the host process. */
#ifdef ECL_THREADS
ecl_thread_t thread;
int cleanup;
#endif
/* -- System Interrupts ---------------------------------------------- */