line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IPC::Pleather; |
2
|
|
|
|
|
|
|
# ABSTRACT: Easy to use concurrency primitives inspired by Cilk |
3
|
|
|
|
|
|
|
$IPC::Pleather::VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
455064
|
use strict; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
70
|
|
6
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
57
|
|
7
|
3
|
|
|
3
|
|
1839
|
use AnyEvent; |
|
3
|
|
|
|
|
11660
|
|
|
3
|
|
|
|
|
96
|
|
8
|
3
|
|
|
3
|
|
912
|
use AnyEvent::Util qw(fork_call); |
|
3
|
|
|
|
|
25887
|
|
|
3
|
|
|
|
|
209
|
|
9
|
3
|
|
|
3
|
|
801
|
use IPC::Semaphore; |
|
3
|
|
|
|
|
12992
|
|
|
3
|
|
|
|
|
95
|
|
10
|
3
|
|
|
3
|
|
18
|
use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT IPC_NOWAIT); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
150
|
|
11
|
3
|
|
|
3
|
|
1726
|
use Keyword::Declare; |
|
3
|
|
|
|
|
242815
|
|
|
3
|
|
|
|
|
32
|
|
12
|
3
|
|
|
3
|
|
505
|
use Guard; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1267
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# IPC |
16
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
our $PID = $$; |
18
|
|
|
|
|
|
|
our $SEM = IPC::Semaphore->new(IPC_PRIVATE, 1, S_IRUSR|S_IWUSR|IPC_CREAT); |
19
|
|
|
|
|
|
|
our $DEPTH = 0; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $SEMGUARD = guard { |
22
|
|
|
|
|
|
|
$SEM->remove; |
23
|
|
|
|
|
|
|
undef $SEM; |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sset($AnyEvent::Util::MAX_FORKS); |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
3
|
0
|
15
|
sub sset { $SEM->setval(0, $_[0]) } |
29
|
25
|
|
|
25
|
0
|
244
|
sub sdec { $SEM->op(0, -1, IPC_NOWAIT) } |
30
|
25
|
|
|
25
|
0
|
194
|
sub sinc { $SEM->op(0, 1, IPC_NOWAIT) } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub spawn { |
33
|
309
|
|
|
309
|
1
|
34044
|
my ($code, @args) = @_; |
34
|
|
|
|
|
|
|
|
35
|
309
|
100
|
66
|
|
|
1200
|
if (!$AnyEvent::CondVar::Base::WAITING && sdec) { |
36
|
25
|
|
|
|
|
2803
|
my $cv = AE::cv; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
fork_call { |
39
|
0
|
|
|
0
|
|
0
|
++$DEPTH; |
40
|
0
|
|
|
|
|
0
|
my ($code, @args) = @_; |
41
|
0
|
|
|
|
|
0
|
$code->(@args); |
42
|
|
|
|
|
|
|
} $code, @args, |
43
|
|
|
|
|
|
|
sub { |
44
|
25
|
100
|
|
25
|
|
157623
|
if (@_) { |
45
|
22
|
|
|
|
|
162
|
$cv->send(@_); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
3
|
|
|
|
|
18
|
eval{ $cv->send($code->(@args)) }; |
|
3
|
|
|
|
|
20
|
|
49
|
3
|
100
|
|
|
|
146
|
$@ && $cv->croak($@); |
50
|
|
|
|
|
|
|
} |
51
|
25
|
|
|
|
|
470
|
sinc; |
52
|
25
|
|
|
|
|
11467
|
}; |
53
|
|
|
|
|
|
|
|
54
|
25
|
|
|
|
|
39417
|
return $cv; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
284
|
|
|
|
|
737
|
return $code->(@args); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
62
|
|
|
|
|
|
|
# Keyword expansions |
63
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
64
|
3
|
|
|
3
|
|
25
|
sub import { |
|
0
|
|
|
|
|
|
|
65
|
3
|
50
|
50
|
|
|
60
|
keyword sync (ScalarVar $var) |
66
|
3
|
|
|
|
|
13
|
{{{ |
67
|
|
|
|
|
|
|
<{$var}> = ((ref(<{$var}>) || '') eq 'AnyEvent::CondVar') ? <{$var}>->recv : <{$var}>; |
68
|
|
|
|
|
|
|
}}} |
69
|
3
|
|
|
|
|
86
|
|
70
|
4
|
50
|
50
|
4
|
|
227949
|
keyword spawn (VarDecl $var, '=', Block $block, CommaList $arg_list, ';') |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
29
|
|
71
|
4
|
|
|
|
|
8
|
{{{ |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
32
|
|
|
3
|
|
|
|
|
11
|
|
72
|
3
|
|
|
|
|
18
|
<{$var}> = IPC::Pleather::spawn(sub <{$block}>, <{$arg_list}>); |
73
|
|
|
|
|
|
|
}}} |
74
|
3
|
|
|
3
|
|
89057
|
|
|
3
|
|
|
|
|
76
|
|
75
|
4
|
50
|
50
|
4
|
|
532975
|
keyword spawn (VarDecl $var, '=', Ident $sub, '(', CommaList $arg_list, ')', ';') |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
26
|
|
76
|
4
|
|
|
|
|
8
|
{{{ |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
32
|
|
|
3
|
|
|
|
|
10
|
|
77
|
3
|
|
|
|
|
13
|
spawn <{$var}> = { <{$sub}>(@_) } <{$arg_list}>; |
78
|
0
|
|
|
|
|
0
|
}}} |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
79
|
0
|
|
|
3
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
91744
|
|
|
3
|
|
|
|
|
70
|
|
80
|
3
|
50
|
50
|
4
|
|
21
|
keyword spawn (VarDecl $var, '=', Ident $sub, Var|Statement|CommaList $arg_or_args, ';') |
|
4
|
|
|
|
|
531638
|
|
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
24
|
|
|
4
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
23
|
|
81
|
4
|
|
|
|
|
12
|
{{{ |
|
4
|
|
|
|
|
36
|
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
28
|
|
|
3
|
|
|
|
|
10
|
|
82
|
3
|
|
|
|
|
15
|
spawn <{$var}> = <{$sub}>(<{$arg_or_args}>); |
83
|
0
|
|
|
|
|
0
|
}}} |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
84
|
0
|
|
|
3
|
|
0
|
} |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
104519
|
|
85
|
3
|
|
|
2
|
|
22
|
|
|
2
|
|
|
|
|
245471
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
4
|
|
86
|
2
|
|
|
|
|
40
|
1; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
14
|
|
87
|
3
|
|
|
|
|
13
|
|
88
|
0
|
|
|
|
|
0
|
__END__ |