From 79e69ec7151662ef6fcb149008d4baab4c4a682c Mon Sep 17 00:00:00 2001 From: glass Date: Tue, 14 Jan 2014 12:14:48 +0000 Subject: * 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 --- ext/thread/thread.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ext/thread') diff --git a/ext/thread/thread.c b/ext/thread/thread.c index 208d1172df..5fb51fe756 100644 --- a/ext/thread/thread.c +++ b/ext/thread/thread.c @@ -502,6 +502,20 @@ rb_szqueue_pop(int argc, VALUE *argv, VALUE self) return szqueue_do_pop(self, should_block); } +/* + * 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 * @@ -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. */ -- cgit v1.2.3