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

ruby-changes:33025

From: naruse <ko1@a...>
Date: Sat, 22 Feb 2014 13:21:44 +0900 (JST)
Subject: [ruby-changes:33025] naruse:r45104 (ruby_2_1): merge revision(s) 44595: [Backport #9342]

naruse	2014-02-22 13:21:39 +0900 (Sat, 22 Feb 2014)

  New Revision: 45104

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

  Log:
    merge revision(s) 44595: [Backport #9342]
    
    * ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
      on SizedQueue#clear. [ruby-core:59462] [Bug #9342]
    
    * test/thread/test_queue.rb: add test. the patch is from
      Justin Collins.

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/ext/thread/thread.c
    branches/ruby_2_1/test/thread/test_queue.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 45103)
+++ ruby_2_1/ChangeLog	(revision 45104)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Sat Feb 22 13:17:32 2014  Masaki Matsushita  <glass.saga@g...>
+
+	* ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
+	  on SizedQueue#clear. [ruby-core:59462] [Bug #9342]
+
+	* test/thread/test_queue.rb: add test. the patch is from
+	  Justin Collins.
+
 Sat Feb 22 01:35:02 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in: check if pthread_setname_np is available.
Index: ruby_2_1/ext/thread/thread.c
===================================================================
--- ruby_2_1/ext/thread/thread.c	(revision 45103)
+++ ruby_2_1/ext/thread/thread.c	(revision 45104)
@@ -503,6 +503,20 @@ rb_szqueue_pop(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/thread/thread.c#L503
 }
 
 /*
+ * Document-method: Queue#clear
+ *
+ * Removes all objects from the queue.
+ */
+
+static VALUE
+rb_szqueue_clear(VALUE self)
+{
+    rb_ary_clear(GET_QUEUE_QUE(self));
+    wakeup_all_threads(GET_SZQUEUE_WAITERS(self));
+    return self;
+}
+
+/*
  * Document-method: SizedQueue#num_waiting
  *
  * Returns the number of threads waiting on the queue.
@@ -586,6 +600,7 @@ Init_thread(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/thread/thread.c#L600
     rb_define_method(rb_cSizedQueue, "max=", rb_szqueue_max_set, 1);
     rb_define_method(rb_cSizedQueue, "push", rb_szqueue_push, 1);
     rb_define_method(rb_cSizedQueue, "pop", rb_szqueue_pop, -1);
+    rb_define_method(rb_cSizedQueue, "clear", rb_szqueue_clear, 0);
     rb_define_method(rb_cSizedQueue, "num_waiting", rb_szqueue_num_waiting, 0);
 
     /* Alias for #push. */
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 45103)
+++ ruby_2_1/version.h	(revision 45104)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.1"
 #define RUBY_RELEASE_DATE "2014-02-22"
-#define RUBY_PATCHLEVEL 50
+#define RUBY_PATCHLEVEL 51
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 2
Index: ruby_2_1/test/thread/test_queue.rb
===================================================================
--- ruby_2_1/test/thread/test_queue.rb	(revision 45103)
+++ ruby_2_1/test/thread/test_queue.rb	(revision 45104)
@@ -129,6 +129,28 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/thread/test_queue.rb#L129
     assert_same q, retval
   end
 
+  def test_sized_queue_clear
+    # Fill queue, then test that SizedQueue#clear wakes up all waiting threads
+    sq = SizedQueue.new(2)
+    2.times { sq << 1 }
+
+    t1 = Thread.new do
+      sq << 1
+    end
+
+    t2 = Thread.new do
+      sq << 1
+    end
+
+    t3 = Thread.new do
+      Thread.pass
+      sq.clear
+    end
+
+    [t3, t2, t1].each(&:join)
+    assert_equal sq.length, 2
+  end
+
   def test_sized_queue_push_return_value
     q = SizedQueue.new(1)
     retval = q.push(1)

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r44595


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

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