diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-14 12:14:48 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-14 12:14:48 +0000 |
commit | 79e69ec7151662ef6fcb149008d4baab4c4a682c (patch) | |
tree | 7c9fdec0248d41ea12244ee42acf7894c4db8fca /ext/thread/thread.c | |
parent | 0a8988c132164a3a39508fabb863f82c22f7063a (diff) | |
download | ruby-79e69ec7151662ef6fcb149008d4baab4c4a682c.tar.gz |
* 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/thread.c')
-rw-r--r-- | ext/thread/thread.c | 15 |
1 files changed, 15 insertions, 0 deletions
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 @@ -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. */ |