summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-19 10:22:53 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-19 10:22:53 +0000
commit6c56dae4b23c5c50e351758538141ca26b9aba40 (patch)
tree18a5e9a00fe481c744c9ed5ef9cb559dab6647a9 /thread.c
parent58282ed667d720816366c9e45c3560904196d078 (diff)
* 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
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/thread.c b/thread.c
index 4a3aeaa396..bf5cb9be61 100644
--- a/thread.c
+++ b/thread.c
@@ -4286,6 +4286,23 @@ rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg)
}
/*
+ * 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
*/
static void
@@ -4740,6 +4757,7 @@ Init_Thread(void)
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_mutex_synchronize_m, 0);
recursive_key = rb_intern("__recursive_key__");
rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);