shutdown custodian and call atexit handlers at place exit

This commit is contained in:
Kevin Tew 2011-05-04 10:36:15 -06:00
parent b74c9f9df3
commit 940e4cce34
4 changed files with 25 additions and 17 deletions

View File

@ -511,6 +511,10 @@ Scheme_Env *scheme_place_instance_init(void *stack_base) {
}
void scheme_place_instance_destroy() {
/* shutdown custodian */
/* run atexit handlers to flush file ports */
scheme_run_atexit_closers();
scheme_end_futures_per_place();
#if defined(MZ_USE_PLACES)
scheme_kill_green_thread_timer();

View File

@ -556,15 +556,6 @@ scheme_init_port (Scheme_Env *env)
}
#endif
#ifdef MZ_FDS
scheme_add_atexit_closer(flush_if_output_fds);
/* Note: other threads might continue to write even after
the flush completes, but that's the threads' problem.
All writing by the main thread will get flushed on exit
(but not, of course, if the thread is shutdown via a
custodian). */
#endif
register_port_wait();
scheme_add_global_constant("subprocess", scheme_make_prim_w_arity2(subprocess, "subprocess", 4, -1, 4, 4), env);
@ -588,6 +579,16 @@ scheme_init_port (Scheme_Env *env)
void scheme_init_port_places(void)
{
#ifdef MZ_FDS
scheme_add_atexit_closer(flush_if_output_fds);
/* Note: other threads might continue to write even after
the flush completes, but that's the threads' problem.
All writing by the main thread will get flushed on exit
(but not, of course, if the thread is shutdown via a
custodian). */
#endif
REGISTER_SO(read_string_byte_buffer);
REGISTER_SO(scheme_orig_stdout_port);
REGISTER_SO(scheme_orig_stderr_port);

View File

@ -558,6 +558,7 @@ typedef struct Scheme_Custodian_Box {
Scheme_Thread *scheme_do_close_managed(Scheme_Custodian *m, Scheme_Exit_Closer_Func f);
Scheme_Custodian *scheme_get_current_custodian(void);
void scheme_run_atexit_closers(void);
typedef struct Scheme_Security_Guard {
Scheme_Object so;

View File

@ -1692,14 +1692,16 @@ static void run_closers(Scheme_Object *o, Scheme_Close_Custodian_Client *f, void
{
Scheme_Object *l;
for (l = cust_closers; SCHEME_RPAIRP(l); l = SCHEME_CDR(l)) {
Scheme_Exit_Closer_Func cf;
cf = (Scheme_Exit_Closer_Func)SCHEME_CAR(l);
cf(o, f, data);
if (cust_closers) {
for (l = cust_closers; SCHEME_RPAIRP(l); l = SCHEME_CDR(l)) {
Scheme_Exit_Closer_Func cf;
cf = (Scheme_Exit_Closer_Func)SCHEME_CAR(l);
cf(o, f, data);
}
}
}
static void run_atexit_closers(void)
void scheme_run_atexit_closers(void)
{
mz_jmp_buf newbuf, *savebuf;
@ -1726,12 +1728,12 @@ void scheme_add_atexit_closer(Scheme_Exit_Closer_Func f)
{
if (!cust_closers) {
if (replacement_at_exit) {
replacement_at_exit(run_atexit_closers);
replacement_at_exit(scheme_run_atexit_closers);
} else {
#ifdef USE_ON_EXIT_FOR_ATEXIT
on_exit(run_atexit_closers, NULL);
on_exit(scheme_run_atexit_closers, NULL);
#else
atexit(run_atexit_closers);
atexit(scheme_run_atexit_closers);
#endif
}