diff --git a/src/c/main.d b/src/c/main.d index cac637d83..9dbb8b350 100644 --- a/src/c/main.d +++ b/src/c/main.d @@ -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; { diff --git a/src/c/process.d b/src/c/process.d index fc26b971b..aec804237 100644 --- a/src/c/process.d +++ b/src/c/process.d @@ -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 diff --git a/src/h/external.h b/src/h/external.h index e5bd86c04..9cebc9f4b 100755 --- a/src/h/external.h +++ b/src/h/external.h @@ -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 ---------------------------------------------- */