[前][次][番号順一覧][スレッド一覧]

ruby-changes:25667

From: kosaki <ko1@a...>
Date: Mon, 19 Nov 2012 19:24:27 +0900 (JST)
Subject: [ruby-changes:25667] kosaki:r37724 (trunk): * prelude.rb: Moved Mutex#synchronize to

kosaki	2012-11-19 19:22:53 +0900 (Mon, 19 Nov 2012)

  New Revision: 37724

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37724

  Log:
    * prelude.rb: Moved Mutex#synchronize to
    * thread.c (rb_mutex_synchronize_m): here. [Bug #4266]

  Modified files:
    trunk/ChangeLog
    trunk/prelude.rb
    trunk/thread.c

Index: prelude.rb
===================================================================
--- prelude.rb	(revision 37723)
+++ prelude.rb	(revision 37724)
@@ -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
   MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37723)
+++ ChangeLog	(revision 37724)
@@ -1,3 +1,8 @@
+Tue Nov 20 09:20:49 2012  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* 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@g...>
 
 	* signal.c (sig_signame): implements Signal.signame method
Index: thread.c
===================================================================
--- thread.c	(revision 37723)
+++ thread.c	(revision 37724)
@@ -4286,6 +4286,23 @@
 }
 
 /*
+ * 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 @@
     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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]