Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* 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
  • Loading branch information...
commit 6c56dae4b23c5c50e351758538141ca26b9aba40 1 parent 58282ed
kosaki authored November 19, 2012
5  ChangeLog
... ...
@@ -1,3 +1,8 @@
  1
+Tue Nov 20 09:20:49 2012  KOSAKI Motohiro  <kosaki.motohiro@gmail.com>
  2
+
  3
+	* prelude.rb: Moved Mutex#synchronize to
  4
+	* thread.c (rb_mutex_synchronize_m): here. [Bug #4266]
  5
+
1 6
 Tue Nov 20 08:36:15 2012  KOSAKI Motohiro  <kosaki.motohiro@gmail.com>
2 7
 
3 8
 	* signal.c (sig_signame): implements Signal.signame method
16  prelude.rb
... ...
@@ -1,19 +1,3 @@
1  
-class Mutex
2  
-  # call-seq:
3  
-  #    mutex.synchronize { ... }
4  
-  #
5  
-  # Obtains a lock, runs the block, and releases the lock when the
6  
-  # block completes.  See the example under Mutex.
7  
-  def synchronize
8  
-    self.lock
9  
-    begin
10  
-      yield
11  
-    ensure
12  
-      self.unlock rescue nil
13  
-    end
14  
-  end
15  
-end
16  
-
17 1
 class Thread
18 2
   MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:
19 3
 
18  thread.c
@@ -4286,6 +4286,23 @@ rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg)
4286 4286
 }
4287 4287
 
4288 4288
 /*
  4289
+ * call-seq:
  4290
+ *    mutex.synchronize { ... }    -> result of the block
  4291
+ *
  4292
+ * Obtains a lock, runs the block, and releases the lock when the block
  4293
+ * completes.  See the example under +Mutex+.
  4294
+ */
  4295
+static VALUE
  4296
+rb_mutex_synchronize_m(VALUE self, VALUE args)
  4297
+{
  4298
+    if (!rb_block_given_p()) {
  4299
+	rb_raise(rb_eThreadError, "must be called with a block");
  4300
+    }
  4301
+
  4302
+    return rb_mutex_synchronize(self, rb_yield, Qnil);
  4303
+}
  4304
+
  4305
+/*
4289 4306
  * Document-class: ThreadShield
4290 4307
  */
4291 4308
 static void
@@ -4740,6 +4757,7 @@ Init_Thread(void)
4740 4757
     rb_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
4741 4758
     rb_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0);
4742 4759
     rb_define_method(rb_cMutex, "sleep", mutex_sleep, -1);
  4760
+    rb_define_method(rb_cMutex, "synchronize", rb_mutex_synchronize_m, 0);
4743 4761
 
4744 4762
     recursive_key = rb_intern("__recursive_key__");
4745 4763
     rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);

0 notes on commit 6c56dae

Please sign in to comment.
Something went wrong with that request. Please try again.