Revision: 4422 http://trac.macosforge.org/projects/ruby/changeset/4422 Author: martinlagardette@apple.com Date: 2010-08-11 13:42:44 -0700 (Wed, 11 Aug 2010) Log Message: ----------- `Mutex#try_unlock`: Add the mutex to the current thread mutexes on success - Fixes #847 Modified Paths: -------------- MacRuby/trunk/thread.c Modified: MacRuby/trunk/thread.c =================================================================== --- MacRuby/trunk/thread.c 2010-08-11 01:55:41 UTC (rev 4421) +++ MacRuby/trunk/thread.c 2010-08-11 20:42:44 UTC (rev 4422) @@ -1363,10 +1363,18 @@ static VALUE rb_mutex_trylock(VALUE self, SEL sel) { - if (pthread_mutex_trylock(&GetMutexPtr(self)->mutex) == 0) { - GetMutexPtr(self)->thread = GetThreadPtr(rb_vm_current_thread()); + rb_vm_mutex_t *m = GetMutexPtr(self); + + if (pthread_mutex_trylock(&m->mutex) == 0) { + rb_vm_thread_t *current = GetThreadPtr(rb_vm_current_thread()); + m->thread = current; + if (current->mutexes == Qnil) { + GC_WB(¤t->mutexes, rb_ary_new()); + } + rb_ary_push(current->mutexes, self); return Qtrue; } + return Qfalse; }