line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::AggressiveIdle; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
98051
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
181
|
|
4
|
2
|
|
|
2
|
|
11
|
use AnyEvent; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
35
|
|
5
|
2
|
|
|
2
|
|
2234
|
use AnyEvent::Util; |
|
2
|
|
|
|
|
30168
|
|
|
2
|
|
|
|
|
187
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
54
|
use 5.010001; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
104
|
|
8
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
9
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1311
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT = qw(aggressive_idle); |
17
|
|
|
|
|
|
|
our @EXPORT_OK = qw(stop_aggressive_idle aggressive_idle); |
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [@EXPORT_OK] ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub stop_aggressive_idle($) { |
21
|
5
|
|
|
5
|
1
|
10
|
our (%IDLE, $WATCHER); |
22
|
|
|
|
|
|
|
|
23
|
5
|
|
|
|
|
16
|
my ($no) = @_; |
24
|
|
|
|
|
|
|
|
25
|
5
|
50
|
33
|
|
|
64
|
croak "Invalid idle identifier: $no" |
|
|
|
33
|
|
|
|
|
26
|
|
|
|
|
|
|
unless $no and !ref($no) and exists $IDLE{$no}; |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
18
|
delete $IDLE{$no}; |
29
|
5
|
100
|
|
|
|
16
|
undef $WATCHER unless %IDLE; |
30
|
5
|
|
|
|
|
197
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _watcher |
34
|
|
|
|
|
|
|
{ |
35
|
38735
|
|
|
38735
|
|
240653
|
our ($WATCHER, $WOBJ, %IDLE); |
36
|
|
|
|
|
|
|
# localize keys (because idle processes can change |
37
|
|
|
|
|
|
|
# watchers list) |
38
|
38735
|
|
|
|
|
77416
|
my @pid = keys %IDLE; |
39
|
38735
|
|
|
|
|
56707
|
for my $p (@pid) { |
40
|
62579
|
50
|
|
|
|
124243
|
next unless exists $IDLE{$p}; |
41
|
62579
|
100
|
|
|
|
178789
|
next unless defined $IDLE{$p}; |
42
|
|
|
|
|
|
|
|
43
|
50668
|
|
|
|
|
72176
|
my $cb = $IDLE{$p}; |
44
|
50668
|
|
|
|
|
57391
|
$IDLE{$p} = undef; |
45
|
|
|
|
|
|
|
|
46
|
50668
|
|
|
|
|
51733
|
my $done = 0; |
47
|
|
|
|
|
|
|
{ |
48
|
50668
|
|
|
|
|
52686
|
my $guard = guard { |
49
|
50667
|
|
|
50667
|
|
182101
|
$done = 1; |
50
|
|
|
|
|
|
|
# do not restart idle process if user has stopped it |
51
|
50667
|
50
|
|
|
|
111384
|
if (exists $IDLE{$p}) { |
52
|
50667
|
|
|
|
|
66595
|
$IDLE{$p} = $cb; |
53
|
50667
|
50
|
|
|
|
249375
|
return if $WATCHER; |
54
|
0
|
|
|
|
|
0
|
$WATCHER = AE::io $WOBJ, 1, \&_watcher; |
55
|
|
|
|
|
|
|
} |
56
|
50668
|
|
|
|
|
204958
|
}; |
57
|
50668
|
|
|
|
|
112226
|
$cb->($p, $guard); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
50668
|
100
|
|
|
|
196638
|
unless ($done) { |
61
|
11
|
50
|
|
|
|
75
|
undef $WATCHER unless %IDLE; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub aggressive_idle(&) { |
67
|
6
|
|
|
6
|
1
|
472927
|
our ($WOBJ, $WOBJR, %IDLE, $WATCHER, $NO); |
68
|
6
|
100
|
|
|
|
30
|
($WOBJR, $WOBJ) = portable_pipe unless defined $WOBJ; |
69
|
6
|
100
|
|
|
|
82
|
$NO = 0 unless defined $NO; |
70
|
|
|
|
|
|
|
|
71
|
6
|
100
|
|
|
|
58
|
$WATCHER = AE::io $WOBJ, 1, \&_watcher unless %IDLE; |
72
|
|
|
|
|
|
|
|
73
|
6
|
|
|
|
|
11
|
my $no = ++$NO; |
74
|
6
|
|
|
|
|
20
|
$IDLE{$no} = $_[0]; |
75
|
|
|
|
|
|
|
|
76
|
6
|
100
|
|
|
|
21
|
return unless defined wantarray; |
77
|
5
|
|
|
5
|
|
35
|
return guard { stop_aggressive_idle $no }; |
|
5
|
|
|
|
|
3317
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |