From 4ece70632d3a2c1a22496b947d86d0efee504650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Tue, 3 Dec 2024 11:20:19 +0100 Subject: [PATCH] modules: [9/n] introduce ecl_module_thread --- src/c/main.d | 15 +++-------- src/c/threads/thread.d | 56 ++++++++++++++++++++++++++++++++++++++++-- src/h/internal.h | 6 ++--- 3 files changed, 60 insertions(+), 17 deletions(-) diff --git a/src/c/main.d b/src/c/main.d index 3177f19ca..e35ba441a 100644 --- a/src/c/main.d +++ b/src/c/main.d @@ -42,17 +42,6 @@ const char *ecl_self; static int ARGC; static char **ARGV; -void -ecl_init_first_env(cl_env_ptr the_env) -{ - the_env->default_sigmask = ecl_core.first_env->default_sigmask; -#ifdef ECL_THREADS - init_threads(); -#else - ecl_cs_init(env); -#endif -} - void ecl_init_env(cl_env_ptr env) { @@ -244,6 +233,9 @@ cl_boot(int argc, char **argv) ecl_add_module(ecl_module_stacks); ecl_add_module(ecl_module_gc); ecl_add_module(ecl_module_unixint); +#ifdef ECL_THREADS + ecl_add_module(ecl_module_thread); +#endif ecl_add_module(ecl_module_bignum); ecl_add_module(ecl_module_ffi); ecl_add_module(ecl_module_aux); @@ -255,7 +247,6 @@ cl_boot(int argc, char **argv) */ env = ecl_core.first_env; - ecl_init_first_env(env); /* We need to enable GC because a lot of stuff is to be created */ ecl_module_gc->module.enable(); diff --git a/src/c/threads/thread.d b/src/c/threads/thread.d index d770b2533..6f82d7ceb 100644 --- a/src/c/threads/thread.d +++ b/src/c/threads/thread.d @@ -474,12 +474,17 @@ mp_restore_signals(cl_object sigmask) #endif } -/* -- Initialization ------------------------------------------------ */ +/* -- Module definition --------------------------------------------- */ void init_threads() { - cl_env_ptr the_env = ecl_process_env(); +} + +static cl_object +create_thread() +{ + cl_env_ptr the_env = ecl_core.first_env; cl_object process, _env = ecl_cast_ptr(cl_object,the_env); /* We have to set the environment before any allocation takes place, * so that the interrupt handling code works. */ @@ -493,4 +498,51 @@ init_threads() ecl_cond_var_init(&process->process.exit_barrier); the_env->own_process = process; ecl_stack_push(ecl_core.threads, _env); + return ECL_NIL; } + +static cl_object +enable_thread() +{ + return ECL_NIL; +} + +static cl_object +init_env_thread(cl_env_ptr the_env) +{ + return ECL_NIL; +} + +static cl_object +init_cpu_thread(cl_env_ptr the_env) +{ + return ECL_NIL; +} + +static cl_object +free_cpu_thread(cl_env_ptr the_env) +{ + return ECL_NIL; +} + +static cl_object +free_env_thread(cl_env_ptr the_env) +{ + return ECL_NIL; +} + +ecl_def_ct_base_string(str_thread, "THREAD", 6, static, const); + +static struct ecl_module module_thread = { + .name = str_thread, + .create = create_thread, + .enable = enable_thread, + .init_env = init_env_thread, + .init_cpu = init_cpu_thread, + .free_cpu = free_cpu_thread, + .free_env = free_env_thread, + .disable = ecl_module_no_op, + .destroy = ecl_module_no_op +}; + +cl_object ecl_module_thread = (cl_object)&module_thread; diff --git a/src/h/internal.h b/src/h/internal.h index 5da058108..615b46c0f 100755 --- a/src/h/internal.h +++ b/src/h/internal.h @@ -28,6 +28,9 @@ extern ECL_API cl_object ecl_module_stacks; extern ECL_API cl_object ecl_module_dummy; extern ECL_API cl_object ecl_module_gc; extern ECL_API cl_object ecl_module_unixint; +#ifdef ECL_THREADS +extern ECL_API cl_object ecl_module_thread; +#endif extern ECL_API cl_object ecl_module_bignum; extern ECL_API cl_object ecl_module_ffi; extern ECL_API cl_object ecl_module_aux; @@ -46,9 +49,6 @@ extern void init_unixtime(void); extern void init_compiler(void); extern void init_process(void); extern void init_modules(void); -#ifdef ECL_THREADS -extern void init_threads(void); -#endif extern void ecl_init_env(cl_env_ptr); extern void init_lib_LSP(cl_object);