Bug #4266 » mutex-synchronize-use-c-implementation.patch
prelude.rb | ||
---|---|---|
class Mutex
|
||
# call-seq:
|
||
# mutex.synchronize { ... }
|
||
#
|
||
# Obtains a lock, runs the block, and releases the lock when the
|
||
# block completes. See the example under Mutex.
|
||
def synchronize
|
||
self.lock
|
||
begin
|
||
yield
|
||
ensure
|
||
self.unlock rescue nil
|
||
end
|
||
end
|
||
end
|
||
class Thread
|
||
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:
|
||
thread.c | ||
---|---|---|
return rb_ensure(func, arg, rb_mutex_unlock, mutex);
|
||
}
|
||
static VALUE
|
||
rb_synchronize(VALUE self)
|
||
{
|
||
return rb_mutex_synchronize(self, rb_yield, Qnil);
|
||
}
|
||
/*
|
||
* Document-class: Barrier
|
||
*/
|
||
... | ... | |
rb_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
|
||
rb_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0);
|
||
rb_define_method(rb_cMutex, "sleep", mutex_sleep, -1);
|
||
rb_define_method(rb_cMutex, "synchronize", rb_synchronize, 0);
|
||
recursive_key = rb_intern("__recursive_key__");
|
||
rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
|