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

ruby-changes:16735

From: shugo <ko1@a...>
Date: Fri, 23 Jul 2010 16:18:15 +0900 (JST)
Subject: [ruby-changes:16735] Ruby:r28731 (trunk): * lib/mutex_m.rb (sleep): added Mutex_m#sleep to support ConditionVariable.

shugo	2010-07-23 16:14:54 +0900 (Fri, 23 Jul 2010)

  New Revision: 28731

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

  Log:
    * lib/mutex_m.rb (sleep): added Mutex_m#sleep to support ConditionVariable.

  Added files:
    trunk/test/test_mutex_m.rb
  Modified files:
    trunk/ChangeLog
    trunk/lib/mutex_m.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28730)
+++ ChangeLog	(revision 28731)
@@ -1,3 +1,8 @@
+Fri Jul 23 16:07:32 2010  Shugo Maeda  <shugo@r...>
+
+	* lib/mutex_m.rb (sleep): added Mutex_m#sleep to support
+	  ConditionVariable.
+
 Fri Jul 23 15:09:22 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (RUBY_MINGW32): ignore msvc suffix.
Index: lib/mutex_m.rb
===================================================================
--- lib/mutex_m.rb	(revision 28730)
+++ lib/mutex_m.rb	(revision 28731)
@@ -78,6 +78,10 @@
     @_mutex.unlock
   end
 
+  def sleep(timeout = nil)
+    @_mutex.sleep(timeout)
+  end
+
   private
 
   def mu_initialize
Index: test/test_mutex_m.rb
===================================================================
--- test/test_mutex_m.rb	(revision 0)
+++ test/test_mutex_m.rb	(revision 28731)
@@ -0,0 +1,25 @@
+require 'test/unit'
+require 'thread'
+require 'mutex_m'
+
+class TestMutexM < Test::Unit::TestCase
+  def test_cv_wait
+    o = Object.new
+    o.extend(Mutex_m)
+    c = ConditionVariable.new
+    t = Thread.start {
+      o.synchronize do
+        until foo = o.instance_variable_get(:@foo)
+          c.wait(o)
+        end
+        foo
+      end
+    }
+    sleep(0.0001)
+    o.synchronize do
+      o.instance_variable_set(:@foo, "abc")
+    end
+    c.signal
+    assert_equal "abc", t.value
+  end
+end

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

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