ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Channel.pm
(Generate patch)

Comparing Coro/Coro/Channel.pm (file contents):
Revision 1.47 by root, Wed Feb 13 15:40:33 2008 UTC vs.
Revision 1.48 by root, Wed Mar 12 21:11:14 2008 UTC

34 34
35=item $q = new Coro:Channel $maxsize 35=item $q = new Coro:Channel $maxsize
36 36
37Create a new channel with the given maximum size (unlimited if C<maxsize> 37Create a new channel with the given maximum size (unlimited if C<maxsize>
38is omitted). Giving a size of one gives you a traditional channel, i.e. a 38is omitted). Giving a size of one gives you a traditional channel, i.e. a
39queue that can store only a single element. 39queue that can store only a single element (which means there will be no
40buffering). To buffer one element you have to specify C<2>, and so on.
40 41
41=cut 42=cut
42 43
43sub new { 44sub new {
44 # [\@contents, [$getwait], $maxsize, [$putwait]]; 45 # [\@contents, [$getwait], $maxsize, [$putwait]];
51 52
52=cut 53=cut
53 54
54sub put { 55sub put {
55 push @{$_[0][0]}, $_[1]; 56 push @{$_[0][0]}, $_[1];
56
57 (pop @{$_[0][1]})->ready if @{$_[0][1]}; 57 (pop @{$_[0][1]})->ready if @{$_[0][1]};
58 58
59 while (@{$_[0][0]} >= $_[0][2]) { 59 while (@{$_[0][0]} >= $_[0][2]) {
60 push @{$_[0][3]}, $Coro::current; 60 push @{$_[0][3]}, $Coro::current;
61 &Coro::schedule; 61 &Coro::schedule;
73will be returned. 73will be returned.
74 74
75=cut 75=cut
76 76
77sub get { 77sub get {
78 (pop @{$_[0][3]})->ready if @{$_[0][3]};
79
80 while (!@{$_[0][0]}) { 78 while (!@{$_[0][0]}) {
81 push @{$_[0][1]}, $Coro::current; 79 push @{$_[0][1]}, $Coro::current;
82 &Coro::schedule; 80 &Coro::schedule;
83 } 81 }
84 82
83 (pop @{$_[0][3]})->ready if @{$_[0][3]};
85 shift @{$_[0][0]} 84 shift @{$_[0][0]}
86} 85}
87 86
88sub timed_get { 87sub timed_get {
89 require Coro::Timer; 88 require Coro::Timer;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines