From 8382e4e80035f6a903d16ff8dc3f385e5a6d1958 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Thu, 21 Jan 2010 14:31:56 +0100 Subject: [PATCH] ecl_init_env() split into ecl_init_env and ecl_cs_set_org() so that the former does not need to be executed in the same thread where it is going to be used. --- src/c/main.d | 16 ++------------- src/c/stacks.d | 51 +++++++++++++++++++++++++++--------------------- src/c/threads.d | 1 + src/h/internal.h | 2 +- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/c/main.d b/src/c/main.d index 2cd1ca2bb..36cdd5048 100644 --- a/src/c/main.d +++ b/src/c/main.d @@ -203,8 +203,6 @@ ecl_set_option(int option, cl_fixnum value) void ecl_init_env(cl_env_ptr env) { - char i; - env->c_env = NULL; env->string_pool = Cnil; @@ -221,17 +219,6 @@ ecl_init_env(cl_env_ptr env) env->indent_stack = ecl_alloc_atomic(ECL_PPRINT_INDENTATION_STACK_SIZE * sizeof(short)); env->fmt_aux_stream = ecl_make_string_output_stream(64, 1); #endif -#if !defined(GBC_BOEHM) -# if defined(THREADS) -# error "No means to mark the stack of a thread :-/" -# else - /* Rough estimate. Not very safe. We assume that cl_boot() - * is invoked from the main() routine of the program. - */ - env->cs_org = (char*)(&env); -# endif /* THREADS */ -#endif /* !GBC_BOEHM */ - #ifdef HAVE_LIBFFI env->ffi_args_limit = 0; env->ffi_types = 0; @@ -254,7 +241,7 @@ ecl_init_env(cl_env_ptr env) #endif env->pending_interrupt = Cnil; - init_stacks(env, &i); + init_stacks(env); { int i; @@ -532,6 +519,7 @@ cl_boot(int argc, char **argv) */ init_big(); ecl_init_env(env); + ecl_cs_set_org(env); #if !defined(GBC_BOEHM) /* We need this because a lot of stuff is to be created */ init_GC(); diff --git a/src/c/stacks.d b/src/c/stacks.d index 1b9a3f3d8..d9c5dbf65 100644 --- a/src/c/stacks.d +++ b/src/c/stacks.d @@ -72,6 +72,34 @@ ecl_cs_overflow(void) cs_set_size(env, size); } +void +ecl_cs_set_org(cl_env_ptr env) +{ + /* Rough estimate. Not very safe. We assume that cl_boot() + * is invoked from the main() routine of the program. + */ + env->cs_org = (char*)(&env); + env->cs_barrier = env->cs_org; +#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_STACK) + { + struct rlimit rl; + cl_index size; + getrlimit(RLIMIT_STACK, &rl); + if (rl.rlim_cur != RLIM_INFINITY) { + size = rl.rlim_cur / 2; + if (size > (cl_index)ecl_get_option(ECL_OPT_C_STACK_SIZE)) + ecl_set_option(ECL_OPT_C_STACK_SIZE, size); +#ifdef ECL_DOWN_STACK + env->cs_barrier = env->cs_org - rl.rlim_cur - 1024; +#else + env->cs_barrier = env->cs_org + rl.rlim_cur + 1024; +#endif + } + } +#endif + cs_set_size(env, ecl_get_option(ECL_OPT_C_STACK_SIZE)); +} + /********************* BINDING STACK ************************/ @@ -562,7 +590,7 @@ si_get_limit(cl_object type) } void -init_stacks(cl_env_ptr env, char *new_cs_org) +init_stacks(cl_env_ptr env) { static struct ihs_frame ihs_org = { NULL, NULL, NULL, 0}; cl_index size, margin; @@ -586,27 +614,6 @@ init_stacks(cl_env_ptr env, char *new_cs_org) ihs_org.lex_env = Cnil; ihs_org.index = 0; - env->cs_org = new_cs_org; - env->cs_barrier = new_cs_org; -#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_STACK) - { - struct rlimit rl; - cl_index size; - getrlimit(RLIMIT_STACK, &rl); - if (rl.rlim_cur != RLIM_INFINITY) { - size = rl.rlim_cur / 2; - if (size > (cl_index)ecl_get_option(ECL_OPT_C_STACK_SIZE)) - ecl_set_option(ECL_OPT_C_STACK_SIZE, size); -#ifdef ECL_DOWN_STACK - env->cs_barrier = env->cs_org - rl.rlim_cur - 1024; -#else - env->cs_barrier = env->cs_org + rl.rlim_cur + 1024; -#endif - } - } -#endif - cs_set_size(env, ecl_get_option(ECL_OPT_C_STACK_SIZE)); - #if 0 /* defined(HAVE_SIGPROCMASK) && defined(SA_SIGINFO) && defined(SA_ONSTACK) */ if (ecl_get_option(ECL_OPT_SIGALTSTACK_SIZE)) { stack_t new_stack; diff --git a/src/c/threads.d b/src/c/threads.d index 2349a40d5..3f33dccea 100644 --- a/src/c/threads.d +++ b/src/c/threads.d @@ -154,6 +154,7 @@ thread_entry_point(void *arg) cl_core.processes = CONS(process, cl_core.processes); THREAD_OP_UNLOCK(); ecl_init_env(env); + ecl_cs_set_org(env); env->bindings_hash = process->process.initial_bindings; ecl_enable_interrupts_env(env); env->trap_fpe_bits = process->process.trap_fpe_bits; diff --git a/src/h/internal.h b/src/h/internal.h index ce0292cbe..9e3916cc7 100644 --- a/src/h/internal.h +++ b/src/h/internal.h @@ -38,7 +38,7 @@ extern void init_GC(void); extern void init_macros(void); extern void init_number(void); extern void init_read(void); -extern void init_stacks(cl_env_ptr, char *); +extern void init_stacks(cl_env_ptr); extern void init_unixint(int pass); extern void init_unixtime(void); #ifdef mingw32