8000 merge revision(s) 44595: [Backport #9342] · github/ruby@df38246 · GitHub
[go: up one dir, main page]

Skip to content

Commit df38246

Browse files
committed
merge revision(s) 44595: [Backport ruby#9342]
* ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS on SizedQueue#clear. [ruby-core:59462] [Bug ruby#9342] * test/thread/test_queue.rb: add test. the patch is from Justin Collins. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@45104 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 17ad6f4 commit df38246

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Sat Feb 22 13:17:32 2014 Masaki Matsushita <glass.saga@gmail.com>
2+
3+
* ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
4+
on SizedQueue#clear. [ruby-core:59462] [Bug #9342]
5+
6+
* test/thread/test_queue.rb: add test. the patch is from
7+
Justin Collins.
8+
19
Sat Feb 22 01:35:02 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
210

311
* configure.in: check if pthread_setname_np is available.

ext/thread/thread.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,20 @@ rb_szqueue_pop(int argc, VALUE *argv, VALUE self)
502502
return szqueue_do_pop(self, should_block);
503503
}
504504

505+
/*
506+
* Document-method: Queue#clear
507+
*
508+
* Removes all objects from the queue.
509+
*/
510+
511+
static VALUE
512+
rb_szqueue_clear(VALUE self)
513+
{
514+
rb_ary_clear(GET_QUEUE_QUE(self));
515+
wakeup_all_threads(GET_SZQUEUE_WAITERS(self));
516+
return self;
517+
}
518+
505519
/*
506520
* Document-method: SizedQueue#num_waiting
507521
*
@@ -586,6 +600,7 @@ Init_thread(void)
586600
rb_define_method(rb_cSizedQueue, "max=", rb_szqueue_max_set, 1);
587601
rb_define_method(rb_cSizedQueue, "push", rb_szqueue_push, 1);
588602
rb_define_method(rb_cSizedQueue, "pop", rb_szqueue_pop, -1);
603+
rb_define_method(rb_cSizedQueue, "clear", rb_szqueue_clear, 0);
589604
rb_define_method(rb_cSizedQueue, "num_waiting", rb_szqueue_num_waiting, 0);
590605

591606
/* Alias for #push. */

test/thread/test_queue.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ def test_queue_clear_return_value
129129
assert_same q, retval
130130
end
131131

132+
def test_sized_queue_clear
133+
# Fill queue, then test that SizedQueue#clear wakes up all waiting threads
134+
sq = SizedQueue.new(2)
135+
2.times { sq << 1 }
136+
137+
t1 = Thread.new do
138+
sq << 1
139+
end
140+
141+
t2 = Thread.new do
142+
sq << 1
143+
end
144+
145+
t3 = Thread.new do
146+
Thread.pass
147+
sq.clear
148+
end
149+
150+
[t3, t2, t1].each(&:join)
151+
assert_equal sq.length, 2
152+
end
153+
132154
def test_sized_queue_push_return_value
133155
q = SizedQueue.new(1)
134156
retval = q.push(1)

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.1"
22
#define RUBY_RELEASE_DATE "2014-02-22"
3-
#define RUBY_PATCHLEVEL 50
3+
#define RUBY_PATCHLEVEL 51
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 2

0 commit comments

Comments
 (0)
0