From 65a87eeb8e35301bb11c80b0c4ab01271ba0c537 Mon Sep 17 00:00:00 2001 From: yugui Date: Sun, 28 Dec 2008 09:41:53 +0000 Subject: merges r21096 from trunk into ruby_1_9_1. * thread.c (rb_thread_atfork, rb_thread_atfork_before_exec): DRY. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@21125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index 74242ea11..9e0cebfae 100644 --- a/thread.c +++ b/thread.c @@ -2438,14 +2438,29 @@ clear_coverage(void) } } +static void +rb_thread_atfork_internal(int (*atfork)(st_data_t, st_data_t, st_data_t)) +{ + rb_thread_t *th = GET_THREAD(); + rb_vm_t *vm = th->vm; + VALUE thval = th->self; + vm->main_thread = th; + + st_foreach(vm->living_threads, atfork, (st_data_t)th); + st_clear(vm->living_threads); + st_insert(vm->living_threads, thval, (st_data_t)th->thread_id); + vm->sleeper = 0; + clear_coverage(); +} + static int -terminate_atfork_i(st_data_t key, st_data_t val, rb_thread_t *current_th) +terminate_atfork_i(st_data_t key, st_data_t val, st_data_t current_th) { VALUE thval = key; rb_thread_t *th; GetThreadPtr(thval, th); - if (th != current_th) { + if (th != (rb_thread_t *)current_th) { thread_cleanup_func(th); } return ST_CONTINUE; @@ -2454,27 +2469,18 @@ terminate_atfork_i(st_data_t key, st_data_t val, rb_thread_t *current_th) void rb_thread_atfork(void) { - rb_thread_t *th = GET_THREAD(); - rb_vm_t *vm = th->vm; - VALUE thval = th->self; - vm->main_thread = th; - - st_foreach(vm->living_threads, terminate_atfork_i, (st_data_t)th); - st_clear(vm->living_threads); - st_insert(vm->living_threads, thval, (st_data_t) th->thread_id); - vm->sleeper = 0; - clear_coverage(); + rb_thread_atfork_internal(terminate_atfork_i); rb_reset_random_seed(); } static int -terminate_atfork_before_exec_i(st_data_t key, st_data_t val, rb_thread_t *current_th) +terminate_atfork_before_exec_i(st_data_t key, st_data_t val, st_data_t current_th) { VALUE thval = key; rb_thread_t *th; GetThreadPtr(thval, th); - if (th != current_th) { + if (th != (rb_thread_t *)current_th) { thread_cleanup_func_before_exec(th); } return ST_CONTINUE; @@ -2483,16 +2489,7 @@ terminate_atfork_before_exec_i(st_data_t key, st_data_t val, rb_thread_t *curren void rb_thread_atfork_before_exec(void) { - rb_thread_t *th = GET_THREAD(); - rb_vm_t *vm = th->vm; - VALUE thval = th->self; - vm->main_thread = th; - - st_foreach(vm->living_threads, terminate_atfork_before_exec_i, (st_data_t)th); - st_clear(vm->living_threads); - st_insert(vm->living_threads, thval, (st_data_t) th->thread_id); - vm->sleeper = 0; - clear_coverage(); + rb_thread_atfork_internal(terminate_atfork_before_exec_i); } struct thgroup { -- cgit