… | |
… | |
9 | |
9 | |
10 | sub start_transfer { |
10 | sub start_transfer { |
11 | my $self = shift; |
11 | my $self = shift; |
12 | |
12 | |
13 | my $trans = bless [ $self ], transfer::; |
13 | my $trans = bless [ $self ], transfer::; |
14 | Scalar::Util::weaken($trans->[0]); |
|
|
15 | |
14 | |
16 | push @{$self->{wait}}, $trans; |
15 | push @{$self->{wait}}, $trans; |
17 | Scalar::Util::weaken($self->{wait}[-1]); |
16 | Scalar::Util::weaken($self->{wait}[-1]); |
18 | |
17 | |
|
|
18 | print "ALLOC $Coro::current\n";#d# |
19 | --$self->{conns}; |
19 | --$self->{conns}; |
20 | $self->wake_next; |
20 | $self->wake_next; |
21 | |
21 | |
22 | $trans; |
22 | $trans; |
23 | } |
23 | } |
24 | |
24 | |
25 | sub wake_next { |
25 | sub wake_next { |
26 | my $self = shift; |
26 | my $self = shift; |
27 | |
27 | |
28 | if ($self->{conns} >= 0) { |
28 | while ($self->{conns} >= 0 && @{$self->{wait}}) { |
|
|
29 | print "WAKING some\n";#d# |
29 | while(@{$self->{wait}}) { |
30 | while(@{$self->{wait}}) { |
30 | my $transfer = shift @{$self->{wait}}; |
31 | my $transfer = shift @{$self->{wait}}; |
31 | if ($transfer) { |
32 | if ($transfer) { |
|
|
33 | print "WAKING $transfer\n";#d# |
32 | $transfer->wake; |
34 | $transfer->wake; |
33 | last; |
35 | last; |
34 | } |
36 | } |
35 | } |
37 | } |
36 | } |
38 | } |
… | |
… | |
53 | sub try { |
55 | sub try { |
54 | my $self = shift; |
56 | my $self = shift; |
55 | |
57 | |
56 | unless ($self->[2]) { |
58 | unless ($self->[2]) { |
57 | my $timeout = Coro::Timer::timeout $_[0]; |
59 | my $timeout = Coro::Timer::timeout $_[0]; |
58 | $self->[1] = $Coro::current; |
60 | local $self->[1] = $Coro::current; |
59 | |
61 | |
60 | Coro::schedule; |
62 | Coro::schedule; |
61 | |
63 | print "WOKE $Coro::current\n" if $self->[2]; |
62 | undef $self->[1]; |
|
|
63 | } |
64 | } |
64 | |
65 | |
65 | return $self->[2]; |
66 | return $self->[2]; |
66 | } |
67 | } |
67 | |
68 | |
68 | sub DESTROY { |
69 | sub DESTROY { |
69 | my $self = shift; |
70 | my $self = shift; |
|
|
71 | eval { |
70 | $self->[0]{conns}++; |
72 | $self->[0]{conns}++; |
71 | $self->[0]->wake_next; |
73 | $self->[0]->wake_next; |
|
|
74 | }; |
|
|
75 | print "DESTROY $Coro::current $@\n";#d# |
72 | } |
76 | } |
73 | |
77 | |
74 | package conn; |
78 | package conn; |
75 | |
79 | |
76 | our %blockuri; |
80 | our %blockuri; |