Skip to content

Commit

Permalink
* thread.c (thread_start_func_2): unlock all locking mutexes
Browse files Browse the repository at this point in the history
  before clean up.  [ruby-core:26877]

* thread.c (rb_thread_atfork): no other threads to be joined.

* vm_core.h (rb_thread_lock_unlock, rb_thread_lock_destroy):
  new functions.

* vm.c (ruby_vm_destruct): unlock and destroy global VM lock.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26390 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jan 23, 2010
1 parent 2e5ef26 commit a1d4164
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Sun Jan 24 05:18:34 2010 Nobuyoshi Nakada <[email protected]>

* thread.c (thread_start_func_2): unlock all locking mutexes
before clean up. [ruby-core:26877]

* thread.c (rb_thread_atfork): no other threads to be joined.

* vm_core.h (rb_thread_lock_unlock, rb_thread_lock_destroy):
new functions.

* vm.c (ruby_vm_destruct): unlock and destroy global VM lock.

Sun Jan 24 00:31:39 2010 NARUSE, Yui <[email protected]>

* lib/rdoc/parser/ruby.rb: fix typo.
Expand Down
33 changes: 26 additions & 7 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ rb_thread_debug(
}
#endif

void
rb_thread_lock_unlock(rb_thread_lock_t *lock)
{
native_mutex_unlock(lock);
}

void
rb_thread_lock_destroy(rb_thread_lock_t *lock)
{
native_mutex_destroy(lock);
}

static void
set_unblock_function(rb_thread_t *th, rb_unblock_function_t *func, void *arg,
Expand Down Expand Up @@ -360,6 +371,15 @@ rb_thread_terminate_all(void)
rb_thread_stop_timer_thread();
}

static void
thread_unlock_all_locking_mutexes(rb_thread_t *th)
{
if (th->keeping_mutexes) {
rb_mutex_unlock_all(th->keeping_mutexes, th);
th->keeping_mutexes = NULL;
}
}

static void
thread_cleanup_func_before_exec(void *th_ptr)
{
Expand All @@ -376,11 +396,6 @@ thread_cleanup_func(void *th_ptr)
{
rb_thread_t *th = th_ptr;

/* unlock all locking mutexes */
if (th->keeping_mutexes) {
rb_mutex_unlock_all(th->keeping_mutexes, th);
th->keeping_mutexes = NULL;
}
th->locking_mutex = Qfalse;
thread_cleanup_func_before_exec(th_ptr);
native_thread_destroy(th);
Expand Down Expand Up @@ -500,12 +515,15 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
th->stack = 0;
}
}
thread_cleanup_func(th);
thread_unlock_all_locking_mutexes(th);
if (th != main_th) rb_check_deadlock(th->vm);
if (th->vm->main_thread == th) {
ruby_cleanup(state);
}
native_mutex_unlock(&th->vm->global_vm_lock);
else {
thread_cleanup_func(th);
native_mutex_unlock(&th->vm->global_vm_lock);
}

return 0;
}
Expand Down Expand Up @@ -2739,6 +2757,7 @@ void
rb_thread_atfork(void)
{
rb_thread_atfork_internal(terminate_atfork_i);
GET_THREAD()->join_list_head = 0;
rb_reset_random_seed();
}

Expand Down
2 changes: 2 additions & 0 deletions vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,8 @@ ruby_vm_destruct(void *ptr)
st_free_table(vm->living_threads);
vm->living_threads = 0;
}
rb_thread_lock_unlock(&vm->global_vm_lock);
rb_thread_lock_destroy(&vm->global_vm_lock);
ruby_xfree(vm);
ruby_current_vm = 0;
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
Expand Down
3 changes: 3 additions & 0 deletions vm_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
void rb_threadptr_signal_exit(rb_thread_t *th);
void rb_threadptr_execute_interrupts(rb_thread_t *);

void rb_thread_lock_unlock(rb_thread_lock_t *);
void rb_thread_lock_destroy(rb_thread_lock_t *);

#define RUBY_VM_CHECK_INTS_TH(th) do { \
if (UNLIKELY(th->interrupt_flag)) { \
rb_threadptr_execute_interrupts(th); \
Expand Down

0 comments on commit a1d4164

Please sign in to comment.