Commit | Line | Data |
---|---|---|
d21067e0 | 1 | package Thread::Queue; |
2 | use Thread qw(cond_wait cond_broadcast); | |
3 | ||
4 | sub new { | |
5 | my $class = shift; | |
6 | return bless [@_], $class; | |
7 | } | |
8 | ||
9 | sub dequeue { | |
10 | use attrs qw(locked method); | |
11 | my $q = shift; | |
12 | cond_wait $q until @$q; | |
13 | return shift @$q; | |
14 | } | |
15 | ||
16 | sub enqueue { | |
17 | use attrs qw(locked method); | |
18 | my $q = shift; | |
19 | push(@$q, @_) and cond_broadcast $q; | |
20 | } | |
21 | ||
22 | 1; |