From 952e91ff073a0820bac5560ae73c9374894a9855 Mon Sep 17 00:00:00 2001
From: Eric Wong <e@80x24.org>
Date: Thu, 2 Jan 2014 07:19:49 +0000
Subject: [PATCH] SizedQueue#max= wakes up waiters properly

We were accessing the wrong array and trying to wake up
elements stored in the queue :x
---
 ext/thread/thread.c       | 2 +-
 test/thread/test_queue.rb | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index b8be5d8..80ed141 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -437,7 +437,7 @@ rb_szqueue_max_set(VALUE self, VALUE vmax)
 	diff = max - GET_SZQUEUE_ULONGMAX(self);
     }
     RSTRUCT_SET(self, SZQUEUE_MAX, vmax);
-    while (diff > 0 && !NIL_P(t = rb_ary_shift(GET_QUEUE_QUE(self)))) {
+    while (diff > 0 && !NIL_P(t = rb_ary_shift(GET_SZQUEUE_WAITERS(self)))) {
 	rb_thread_wakeup_alive(t);
     }
     return vmax;
diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb
index 563b91e..7f09f40 100644
--- a/test/thread/test_queue.rb
+++ b/test/thread/test_queue.rb
@@ -55,6 +55,13 @@ class TestQueue < Test::Unit::TestCase
     assert_equal(1, q.max)
     assert_raise(ArgumentError) { q.max = -1 }
     assert_equal(1, q.max)
+
+    before = q.max
+    q.max.times { q << 1 }
+    t1 = Thread.new { q << 1 }
+    sleep 0.01 until t1.stop?
+    q.max = q.max + 1
+    assert_equal before + 1, q.max
   end
 
   def test_queue_pop_interrupt
-- 
1.8.3.2.701.g8c4e4ec

