summaryrefslogtreecommitdiff
path: root/ext/thread
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-14 12:14:48 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-14 12:14:48 +0000
commit79e69ec7151662ef6fcb149008d4baab4c4a682c (patch)
tree7c9fdec0248d41ea12244ee42acf7894c4db8fca /ext/thread
parent0a8988c132164a3a39508fabb863f82c22f7063a (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/thread')
-rw-r--r--ext/thread/thread.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index 208d1172dfb..5fb51fe7569 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -503,6 +503,20 @@ rb_szqueue_pop(int argc, VALUE *argv, VALUE self)
}
/*
+ * 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)
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. */