mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* prelude.rb: Moved Mutex#synchronize to
* thread.c (rb_mutex_synchronize_m): here. [Bug #4266] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
58282ed667
commit
6c56dae4b2
3 changed files with 23 additions and 16 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Nov 20 09:20:49 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* prelude.rb: Moved Mutex#synchronize to
|
||||||
|
* thread.c (rb_mutex_synchronize_m): here. [Bug #4266]
|
||||||
|
|
||||||
Tue Nov 20 08:36:15 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Tue Nov 20 08:36:15 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* signal.c (sig_signame): implements Signal.signame method
|
* signal.c (sig_signame): implements Signal.signame method
|
||||||
|
|
16
prelude.rb
16
prelude.rb
|
@ -1,19 +1,3 @@
|
||||||
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
|
class Thread
|
||||||
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:
|
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:
|
||||||
|
|
||||||
|
|
18
thread.c
18
thread.c
|
@ -4285,6 +4285,23 @@ rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg)
|
||||||
return rb_ensure(func, arg, rb_mutex_unlock, mutex);
|
return rb_ensure(func, arg, rb_mutex_unlock, mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* mutex.synchronize { ... } -> result of the block
|
||||||
|
*
|
||||||
|
* Obtains a lock, runs the block, and releases the lock when the block
|
||||||
|
* completes. See the example under +Mutex+.
|
||||||
|
*/
|
||||||
|
static VALUE
|
||||||
|
rb_mutex_synchronize_m(VALUE self, VALUE args)
|
||||||
|
{
|
||||||
|
if (!rb_block_given_p()) {
|
||||||
|
rb_raise(rb_eThreadError, "must be called with a block");
|
||||||
|
}
|
||||||
|
|
||||||
|
return rb_mutex_synchronize(self, rb_yield, Qnil);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Document-class: ThreadShield
|
* Document-class: ThreadShield
|
||||||
*/
|
*/
|
||||||
|
@ -4740,6 +4757,7 @@ Init_Thread(void)
|
||||||
rb_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
|
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, "unlock", rb_mutex_unlock, 0);
|
||||||
rb_define_method(rb_cMutex, "sleep", mutex_sleep, -1);
|
rb_define_method(rb_cMutex, "sleep", mutex_sleep, -1);
|
||||||
|
rb_define_method(rb_cMutex, "synchronize", rb_mutex_synchronize_m, 0);
|
||||||
|
|
||||||
recursive_key = rb_intern("__recursive_key__");
|
recursive_key = rb_intern("__recursive_key__");
|
||||||
rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
|
rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
|
||||||
|
|
Loading…
Add table
Reference in a new issue