MCE/Child.pm

filter: Statementstmt 69.4% 384 / 553 Branchbran 43.3% 189 / 436 Conditioncond 31.8% 56 / 176 MC/DCmcdc 4.0% 4 / 100 Subroutinesub 71.7% 56 / 78 Podpod 100% 24 / 24 totaltotal 52.1% 713 / 1367 CC 282 SCAR 39.5
CC
282
Cov
54%
create
182.5
init
118.6
_trap
90.0
CRAP 52.1
« MCE/Channel/ThreadsFast.pm ↑ Summary MCE/Channel/Threads.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## A threads-like parallelization module compatible with Perl 5.8.
4 ##
5 ###############################################################################
6  
7 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶no warnings qw( threads recursion uninitialized once redefine );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 package MCE::Child;
13  
14 9 our $VERSION = '1.904';
15  
16 ## no critic (BuiltinFunctions::ProhibitStringyEval)
17 ## no critic (Subroutines::ProhibitExplicitReturnUndef)
18 ## no critic (Subroutines::ProhibitSubroutinePrototypes)
19 ## no critic (TestingAndDebugging::ProhibitNoStrict)
20  
21 9 ▶use MCE::Signal ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 9 ▶use MCE::Mutex ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 9 ▶use MCE::Channel ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 9 ▶use Time::HiRes 'sleep';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 9 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.2
27 q(==) => \&equal,
28 0 ▶ q(!=) => sub { !equal(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 9 fallback => 1
30 9 );
31  
32 9 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
33 9 ▶ if (caller !~ /^MCE::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ((caller) =~ /^MCE::/) 9 0 9
34 9 ▶ no strict 'refs'; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
35 9 *{ caller().'::mce_child' } = \&mce_child;
36 }
37 9 return;
38 }
39  
40 ## The POSIX module has many symbols. Try not loading it simply
41 ## to have WNOHANG. The following covers most platforms.
42  
43 9 ▶use constant {
Subroutine BEGIN: called CC=3 SCAR=11.7
44 9 ▶ _WNOHANG => ( $INC{'POSIX.pm'} )
Branch: 2 branches
BranchTrueFalseTotal
$INC{'POSIX.pm'} ? : 0 9 9
$^O eq 'solaris' ? : 0 9 9
45 ? &POSIX::WNOHANG : ( $^O eq 'solaris' ) ? 64 : 1
46 9 };
47  
48 9 my ( $_MNGD, $_DATA, $_DELY, $_LIST ) = ( {}, {}, {}, {} );
49  
50 9 ▶my $_is_MSWin32 = ( $^O eq 'MSWin32' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 9 9
51 9 ▶my $_tid = ( $INC{'threads.pm'} ) ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 9 9
52 9 ▶my $_yield_secs = ( $^O =~ /mswin|mingw|msys|cygwin/i ) ? 0.015 : 0.008;
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin|mingw|msys|cygwin/i ? : 0 9 9
53  
54 0 ▶sub CLONE {
Subroutine CLONE: not called CC=2 SCAR=17.9
55 0 ▶ $_tid = threads->tid(), &_clear() if $INC{'threads.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 0 0
56 }
57  
58 7 ▶sub _clear {
Subroutine _clear: called CC=1 SCAR=0.0
59 7 %{ $_LIST } = ();
60 }
61  
62 10 ▶sub _max_workers {
Subroutine _max_workers: called CC=5 SCAR=16.1
63 10 my ( $cpus ) = @_;
64 10 ▶ if ( $cpus eq 'auto' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cpus eq 'auto') { } 1 9 10
elsif ($cpus =~ /^([0-9.]+)%$/) { } 6 3 9
65 1 $cpus = MCE::Util::get_ncpu();
66 }
67 elsif ( $cpus =~ /^([0-9.]+)%$/ ) {
68 6 my ( $percent, $ncpu ) = ( $1 / 100, MCE::Util::get_ncpu() );
69 6 $cpus = $ncpu * $percent + 0.5;
70 }
71 10 ▶ $cpus = 1 if $cpus !~ /^[\d\.]+$/ || $cpus < 1;
Branch: 1 branch
BranchTrueFalseTotal
if not $cpus =~ /^[\d\.]+$/ or $cpus < 1 3 7 10
Condition66%2/3
not $cpus =~ /^[\d\.]+$/ or $cpus < 1
l!l&&r!l&&!r
037
MC/DC50%1/2
not $cpus =~ /^[\d\.]+$/ or $cpus < 1
not $cpus =~ /^[\d\.]+$/ $cpus < 1
Truth table66%2/3
not(A) or B
A= not $cpus =~ /^[\d\.]+$/B= $cpus < 1
ABresult
1X1
011
000
72 10 return int($cpus);
73 }
74  
75 ###############################################################################
76 ## ----------------------------------------------------------------------------
77 ## Init routine.
78 ##
79 ###############################################################################
80  
81 9 bless my $_SELF = { MGR_ID => "$$.$_tid", WRK_ID => $$ }, __PACKAGE__;
82  
83 0 ▶sub MCE::Child::_guard::DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=24.8
84 0 my ($pkg, $id) = @{ $_[0] };
85  
86 0 ▶ if (defined $pkg && $id eq "$$.$_tid") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pkg and $id eq "${$}.$_tid") 0 0 0
Condition0%0/3
defined $pkg and $id eq "${$}.$_tid"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pkg and $id eq "${$}.$_tid"
defined $pkg $id eq "${$}.$_tid"
Truth table0%0/3
A and B
A= defined $pkgB= $id eq "${$}.$_tid"
ABresult
0X0
100
111
87 0 @{ $_[0] } = ();
88 0 MCE::Child->finish($pkg);
89 }
90  
91 0 return;
92 }
93  
94 16 ▶sub init {
Subroutine init: called CC=35 SCAR=47.8
Pod documented
95 16 ▶ shift if ( defined $_[0] && $_[0] eq __PACKAGE__ );
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq __PACKAGE__ 8 8 16
Condition66%2/3
defined $_[0] and $_[0] eq __PACKAGE__
!ll&&!rl&&r
088
MC/DC50%1/2
defined $_[0] and $_[0] eq __PACKAGE__
defined $_[0] $_[0] eq __PACKAGE__
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] eq __PACKAGE__
ABresult
0X0
100
111
96  
97 # -- options ----------------------------------------------------------
98 # max_workers child_timeout posix_exit on_start on_finish void_context
99 # ---------------------------------------------------------------------
100  
101 16 ▶ my $opt = ( ref $_[0] eq 'HASH' ) ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 16 16
102 16 ▶ my $pkg = "$$.$_tid.".( delete $opt->{caller} || caller() );
Condition66%2/3
delete $opt->{'caller'} || caller()
l!l&&r!l&&!r
880
MC/DC0%0/2
delete $opt->{'caller'} || caller()
delete $opt->{'caller'} caller()
Truth table66%2/3
A || B
A= delete $opt->{'caller'}B= caller()
ABresult
1X1
011
000
103 16 my $mngd = $_MNGD->{$pkg} = $opt;
104  
105 16 @_ = ();
106  
107 $mngd->{MGR_ID} = "$$.$_tid", $mngd->{PKG} = $pkg,
108 16 $mngd->{WRK_ID} = $$;
109  
110 16 ▶ &_force_reap($pkg), $_DATA->{$pkg}->clear() if ( defined $_LIST->{$pkg} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $_LIST->{$pkg} 7 9 16
111  
112 16 ▶ if ( !defined $_LIST->{$pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_LIST->{$pkg}) 9 7 16
113 9 ▶ $MCE::_GMUTEX->lock() if ( $_tid && $MCE::_GMUTEX );
Branch: 1 branch
BranchTrueFalseTotal
if $_tid and $MCE::_GMUTEX 0 9 9
Condition33%1/3
$_tid and $MCE::_GMUTEX
!ll&&!rl&&r
900
MC/DC0%0/2
$_tid and $MCE::_GMUTEX
$_tid $MCE::_GMUTEX
Truth table33%1/3
A and B
A= $_tidB= $MCE::_GMUTEX
ABresult
0X0
100
111
114 9 ▶ sleep 0.015 if $_tid;
Branch: 1 branch
BranchTrueFalseTotal
if $_tid 0 9 9
115  
116 # Start the shared-manager process if not running.
117 9 ▶ MCE::Shared->start() if $INC{'MCE/Shared.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"MCE/Shared.pm"} 0 9 9
118  
119 9 my $chnl = MCE::Channel->new( impl => 'Mutex' );
120 9 $_LIST->{ $pkg } = MCE::Child::_ordhash->new();
121 9 $_DELY->{ $pkg } = MCE::Child::_delay->new( $chnl );
122 9 $_DATA->{ $pkg } = MCE::Child::_hash->new( $chnl );
123 9 $_DATA->{"$pkg:id"} = 0;
124  
125 9 $_DATA->{"$pkg:seed"} = int(CORE::rand() * 1e9);
126  
127 9 ▶ $MCE::_GMUTEX->unlock() if ( $_tid && $MCE::_GMUTEX );
Branch: 1 branch
BranchTrueFalseTotal
if $_tid and $MCE::_GMUTEX 0 9 9
Condition33%1/3
$_tid and $MCE::_GMUTEX
!ll&&!rl&&r
900
MC/DC0%0/2
$_tid and $MCE::_GMUTEX
$_tid $MCE::_GMUTEX
Truth table33%1/3
A and B
A= $_tidB= $MCE::_GMUTEX
ABresult
0X0
100
111
128 }
129  
130 16 ▶ if ( !exists $mngd->{posix_exit} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $mngd->{"posix_exit"}) 16 0 16
131 $mngd->{posix_exit} = 1 if (
132 $^S || $_tid || $INC{'Mojo/IOLoop.pm'} ||
133 $INC{'Coro.pm'} || $INC{'LWP/UserAgent.pm'} || $INC{'stfl.pm'} ||
134 $INC{'Curses.pm'} || $INC{'CGI.pm'} || $INC{'FCGI.pm'} ||
135 $INC{'Tk.pm'} || $INC{'Wx.pm'} || $INC{'Win32/GUI.pm'} ||
136 16 ▶ $INC{'Gearman/Util.pm'} || $INC{'Gearman/XS.pm'}
Branch: 1 branch
BranchTrueFalseTotal
if $^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"} or $INC{"CGI.pm"} or $INC{"FCGI.pm"} or $INC{"Tk.pm"} or $INC{"Wx.pm"} or $INC{"Win32/GUI.pm"} or $INC{"Gearman/Util.pm"} or $INC{"Gearman/XS.pm"} 0 16 16
Condition33%13/39
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"} or $INC{"CGI.pm"} or $INC{"FCGI.pm"} or $INC{"Tk.pm"} or $INC{"Wx.pm"} or $INC{"Win32/GUI.pm"} or $INC{"Gearman/Util.pm"} or $INC{"Gearman/XS.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"} or $INC{"CGI.pm"} or $INC{"FCGI.pm"} or $INC{"Tk.pm"} or $INC{"Wx.pm"} or $INC{"Win32/GUI.pm"} or $INC{"Gearman/Util.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"} or $INC{"CGI.pm"} or $INC{"FCGI.pm"} or $INC{"Tk.pm"} or $INC{"Wx.pm"} or $INC{"Win32/GUI.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"} or $INC{"CGI.pm"} or $INC{"FCGI.pm"} or $INC{"Tk.pm"} or $INC{"Wx.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"} or $INC{"CGI.pm"} or $INC{"FCGI.pm"} or $INC{"Tk.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"} or $INC{"CGI.pm"} or $INC{"FCGI.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"} or $INC{"CGI.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid or $INC{"Mojo/IOLoop.pm"}
l!l&&r!l&&!r
0016
$^S or $_tid
l!l&&r!l&&!r
0016
MC/DC0%0/14
$^S or $_tid or $INC{"Mojo/IOLoop.pm"} or $INC{"Coro.pm"} or $INC{"LWP/UserAgent.pm"} or $INC{"stfl.pm"} or $INC{"Curses.pm"} or $INC{"CGI.pm"} or $INC{"FCGI.pm"} or $INC{"Tk.pm"} or $INC{"Wx.pm"} or $INC{"Win32/GUI.pm"} or $INC{"Gearman/Util.pm"} or $INC{"Gearman/XS.pm"}
$^S $_tid $INC{"Mojo/IOLoop.pm"} $INC{"Coro.pm"} $INC{"LWP/UserAgent.pm"} $INC{"stfl.pm"} $INC{"Curses.pm"} $INC{"CGI.pm"} $INC{"FCGI.pm"} $INC{"Tk.pm"} $INC{"Wx.pm"} $INC{"Win32/GUI.pm"} $INC{"Gearman/Util.pm"} $INC{"Gearman/XS.pm"}
Truth table6%1/15
A or B or C or D or E or F or G or H or I or J or K or L or M or N
A= $^SB= $_tidC= $INC{"Mojo/IOLoop.pm"}D= $INC{"Coro.pm"}E= $INC{"LWP/UserAgent.pm"}F= $INC{"stfl.pm"}G= $INC{"Curses.pm"}H= $INC{"CGI.pm"}I= $INC{"FCGI.pm"}J= $INC{"Tk.pm"}K= $INC{"Wx.pm"}L= $INC{"Win32/GUI.pm"}M= $INC{"Gearman/Util.pm"}N= $INC{"Gearman/XS.pm"}
ABCDEFGHIJKLMNresult
1XXXXXXXXXXXXX1
01XXXXXXXXXXXX1
001XXXXXXXXXXX1
0001XXXXXXXXXX1
00001XXXXXXXXX1
000001XXXXXXXX1
0000001XXXXXXX1
00000001XXXXXX1
000000001XXXXX1
0000000001XXXX1
00000000001XXX1
000000000001XX1
0000000000001X1
000000000000011
000000000000000
137 );
138 }
139  
140 16 ▶ if ( defined $mngd->{max_workers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mngd->{"max_workers"}) 3 13 16
141 3 $mngd->{max_workers} = _max_workers($mngd->{max_workers});
142 }
143  
144 16 ▶ if ( $INC{'LWP/UserAgent.pm'} && !$INC{'Net/HTTP.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"LWP/UserAgent.pm"} and not $INC{"Net/HTTP.pm"}) 0 16 16
Condition33%1/3
$INC{"LWP/UserAgent.pm"} and not $INC{"Net/HTTP.pm"}
!ll&&!rl&&r
1600
MC/DC0%0/2
$INC{"LWP/UserAgent.pm"} and not $INC{"Net/HTTP.pm"}
$INC{"LWP/UserAgent.pm"} not $INC{"Net/HTTP.pm"}
Truth table33%1/3
A and not(B)
A= $INC{"LWP/UserAgent.pm"}B= not $INC{"Net/HTTP.pm"}
ABresult
0X0
100
111
145 0 local $@; eval 'require Net::HTTP; require Net::HTTPS';
146 }
147  
148 require POSIX
149 16 ▶ if ( $mngd->{on_finish} && !$INC{'POSIX.pm'} && !$_is_MSWin32 );
Branch: 1 branch
BranchTrueFalseTotal
if $mngd->{"on_finish"} and not $INC{"POSIX.pm"} and not $_is_MSWin32 5 11 16
Condition66%4/6
$mngd->{"on_finish"} and not $INC{"POSIX.pm"} and not $_is_MSWin32
!ll&&!rl&&r
1105
$mngd->{"on_finish"} and not $INC{"POSIX.pm"}
!ll&&!rl&&r
1105
MC/DC33%1/3
$mngd->{"on_finish"} and not $INC{"POSIX.pm"} and not $_is_MSWin32
$mngd->{"on_finish"} not $INC{"POSIX.pm"} not $_is_MSWin32
Truth table50%2/4
A and not(B) and not(C)
A= $mngd->{"on_finish"}B= not $INC{"POSIX.pm"}C= not $_is_MSWin32
ABCresult
0XX0
10X0
1100
1111
150  
151 defined wantarray
152 16 ▶ ? bless([$pkg, "$$.$_tid"], MCE::Child::_guard::)
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 16 16
153 : ();
154 }
155  
156 ###############################################################################
157 ## ----------------------------------------------------------------------------
158 ## 'new', 'mce_child', and 'create' for threads-like similarity.
159 ##
160 ###############################################################################
161  
162 ## 'new' and 'tid' are aliases for 'create' and 'pid' respectively.
163  
164 9 *new = \&create, *tid = \&pid;
165  
166 ## Use "goto" trick to avoid pad problems from 5.8.1 (fixed in 5.8.2)
167 ## Tip found in threads::async.
168  
169 0 ▶sub mce_child (&;@) {
Subroutine mce_child: not called CC=1 SCAR=6.9
Pod documented
170 0 goto &create;
171 }
172  
173 50 ▶sub create {
Subroutine create: called CC=41 SCAR=52.1
Pod documented
174 50 my $caller = caller();
175  
176 50 ▶ my $mngd = $_MNGD->{ "$$.$_tid.$caller" } || do {
Condition66%2/3
$$_MNGD{"${$}.$_tid.$caller"} || do { init('caller', $caller); $$_MNGD{"${$}.$_tid.$caller"} }
l!l&&r!l&&!r
4280
MC/DC0%0/2
$$_MNGD{"${$}.$_tid.$caller"} || do { init('caller', $caller); $$_MNGD{"${$}.$_tid.$caller"} }
$$_MNGD{"${$}.$_tid.$caller"} do { init('caller', $caller); $$_MNGD{"${$}.$_tid.$caller"} }
Truth table66%2/3
A || B
A= $$_MNGD{"${$}.$_tid.$caller"}B= do { init('caller', $caller); $$_MNGD{"${$}.$_tid.$caller"} }
ABresult
1X1
011
000
177 # construct mngd internally on first use unless defined
178 8 init( caller => $caller ); $_MNGD->{ "$$.$_tid.$caller" };
179 };
180  
181 50 ▶ shift if ( $_[0] eq __PACKAGE__ );
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq __PACKAGE__ 50 0 50
182  
183 # ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~
184  
185 0 ▶ my $self = bless ref $_[0] eq 'HASH' ? { %{ shift() } } : { }, __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 50 50
186  
187 50 ▶ $self->{IGNORE} = 1 if $SIG{CHLD} eq 'IGNORE';
Branch: 1 branch
BranchTrueFalseTotal
if $SIG{"CHLD"} eq "IGNORE" 0 50 50
188 50 $self->{MGR_ID} = $mngd->{MGR_ID}, $self->{PKG} = $mngd->{PKG};
189 50 ▶ $self->{ident } = shift if ( !ref $_[0] && ref $_[1] eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] and ref $_[1] eq "CODE" 0 50 50
Condition33%1/3
not ref $_[0] and ref $_[1] eq "CODE"
!ll&&!rl&&r
5000
MC/DC0%0/2
not ref $_[0] and ref $_[1] eq "CODE"
not ref $_[0] ref $_[1] eq "CODE"
Truth table33%1/3
not(A) and B
A= not ref $_[0]B= ref $_[1] eq "CODE"
ABresult
0X0
100
111
190  
191 50 ▶ my $func = shift; $func = $caller.'::'.$func
Branch: 1 branch
BranchTrueFalseTotal
if not ref $func and length $func and index($func, ":") == -1 0 50 50
Condition33%2/6
not ref $func and length $func and index($func, ":") == -1
!ll&&!rl&&r
5000
not ref $func and length $func
!ll&&!rl&&r
5000
MC/DC0%0/3
not ref $func and length $func and index($func, ":") == -1
not ref $func length $func index($func, ":") == -1
Truth table25%1/4
not(A) and B and C
A= not ref $funcB= length $funcC= index($func, ":") == -1
ABCresult
0XX0
10X0
1100
1111
192 if ( !ref $func && length $func && index($func,':') < 0 );
193  
194 50 ▶ if ( !defined $func ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $func) 0 50 50
195 0 local $\; print {*STDERR} "code function is not specified or valid\n";
196 0 return undef;
197 }
198  
199 my ( $list, $max_workers, $pkg ) = (
200 $_LIST->{ $mngd->{PKG} }, $mngd->{max_workers}, $mngd->{PKG}
201 50 );
202  
203 50 ▶ $_DATA->{"$pkg:id"} = 10000 if ( ( my $id = ++$_DATA->{"$pkg:id"} ) >= 2e9 );
Branch: 1 branch
BranchTrueFalseTotal
if (my $id = ++$$_DATA{"${pkg}:id"}) >= 2000000000 0 50 50
204  
205 # Reap completed child processes.
206 {
207 50 local ($SIG{CHLD}, $!, $?, $_);
208 map {
209 0 $_ = substr($_, 1); # strip leading 'R'
210 0 my $child = $list->del($_);
211 0 ▶ if ( ! $child->{REAPED} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($child->{"REAPED"}) 0 0 0
212 0 waitpid($child->{WRK_ID}, 0);
213 0 _reap_child($child, 0);
214 }
215 0 ();
216 }
217 50 $_DATA->{$pkg}->get_done();
218 }
219  
220 # Wait for a slot if saturated.
221 50 ▶ _wait_one($pkg) if ( $max_workers && $list->len() >= $max_workers );
Branch: 1 branch
BranchTrueFalseTotal
if $max_workers and $list->len >= $max_workers 0 50 50
Condition33%1/3
$max_workers and $list->len >= $max_workers
!ll&&!rl&&r
5000
MC/DC0%0/2
$max_workers and $list->len >= $max_workers
$max_workers $list->len >= $max_workers
Truth table33%1/3
A and B
A= $max_workersB= $list->len >= $max_workers
ABresult
0X0
100
111
222  
223 # ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~
224  
225 50 ▶ $MCE::_GMUTEX->lock() if ( $_tid && $MCE::_GMUTEX );
Branch: 1 branch
BranchTrueFalseTotal
if $_tid and $MCE::_GMUTEX 0 50 50
Condition33%1/3
$_tid and $MCE::_GMUTEX
!ll&&!rl&&r
5000
MC/DC0%0/2
$_tid and $MCE::_GMUTEX
$_tid $MCE::_GMUTEX
Truth table33%1/3
A and B
A= $_tidB= $MCE::_GMUTEX
ABresult
0X0
100
111
226  
227 50 my @args = @_; @_ = (); # To avoid (Scalars leaked: N) messages
228 50 my ( $killed, $pid );
229  
230 {
231 0 ▶ local $SIG{TERM} = local $SIG{INT} = sub { $killed = $_[0] }
Subroutine __ANON__: not called CC=1 SCAR=1.2
232 50 ▶ if ( !$_is_MSWin32 && $] ge '5.010001' );
Branch: 1 branch
BranchTrueFalseTotal
if not $_is_MSWin32 and $] ge "5.010001" 50 0 50
Condition33%1/3
not $_is_MSWin32 and $] ge "5.010001"
!ll&&!rl&&r
0050
MC/DC0%0/2
not $_is_MSWin32 and $] ge "5.010001"
not $_is_MSWin32 $] ge "5.010001"
Truth table33%1/3
not(A) and B
A= not $_is_MSWin32B= $] ge "5.010001"
ABresult
0X0
100
111
233  
234 local $SIG{TTIN}, local $SIG{TTOU}, local $SIG{WINCH}
235 50 ▶ if ( !$_is_MSWin32 );
Branch: 1 branch
BranchTrueFalseTotal
unless $_is_MSWin32 50 0 50
236  
237 50 $pid = fork();
238  
239 50 ▶ if ( !defined $pid ) { # error
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $pid) { } 0 50 50
elsif ($pid) { } 43 7 50
240 0 local $\; print {*STDERR} "fork error: $!\n";
241 }
242 elsif ( $pid ) { # parent
243 43 $self->{WRK_ID} = $pid;
244 43 $list->set($pid, $self);
245 43 ▶ $mngd->{on_start}->($pid, $self->{ident}) if $mngd->{on_start};
Branch: 1 branch
BranchTrueFalseTotal
if $mngd->{"on_start"} 10 33 43
246 }
247 else { # child
248 7 %{ $_LIST } = (), $_SELF = $self;
249  
250 local $SIG{TERM} = local $SIG{INT} = local $SIG{ABRT} = \&_trap,
251 local $SIG{SEGV} = local $SIG{HUP} = \&_trap,
252 7 local $SIG{QUIT} = \&_quit;
253 7 local $SIG{CHLD};
254  
255 7 ▶ MCE::Shared::init() if $INC{'MCE/Shared.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"MCE/Shared.pm"} 0 7 7
256 7 ▶ $_DATA->{ $_SELF->{PKG} }->set('S'.$$, '') unless $self->{IGNORE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"IGNORE"} 7 0 7
257 7 ▶ CORE::kill($killed, $$) if $killed;
Branch: 1 branch
BranchTrueFalseTotal
if $killed 0 7 7
258  
259 7 ▶ MCE::Child->_clear() if $INC{'MCE/Child.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"MCE/Child.pm"} 7 0 7
260 7 ▶ MCE::Hobo->_clear() if $INC{'MCE/Hobo.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"MCE/Hobo.pm"} 0 7 7
261  
262 # Set the seed of the base generator uniquely between workers.
263 # The new seed is computed using the current seed and ID value.
264 # One may set the seed at the application level for predictable
265 # results. Ditto for PDL, Math::Prime::Util, Math::Random, and
266 # Math::Random::MT::Auto.
267  
268 {
269 7 my $seed = abs($_DATA->{"$pkg:seed"} - ($id * 100000)) % 2147483560;
270  
271 7 CORE::srand($seed);
272 7 ▶ PDL::srand($seed) if $INC{'PDL.pm'} && PDL->can('srand'); # PDL 2.062 ~ 2.089
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"PDL.pm"} and "PDL"->can("srand") 0 7 7
Condition33%1/3
$INC{"PDL.pm"} and "PDL"->can("srand")
!ll&&!rl&&r
700
MC/DC0%0/2
$INC{"PDL.pm"} and "PDL"->can("srand")
$INC{"PDL.pm"} "PDL"->can("srand")
Truth table33%1/3
A and B
A= $INC{"PDL.pm"}B= "PDL"->can("srand")
ABresult
0X0
100
111
273 7 ▶ PDL::srandom($seed) if $INC{'PDL.pm'} && PDL->can('srandom'); # PDL 2.089_01+
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"PDL.pm"} and "PDL"->can("srandom") 0 7 7
Condition33%1/3
$INC{"PDL.pm"} and "PDL"->can("srandom")
!ll&&!rl&&r
700
MC/DC0%0/2
$INC{"PDL.pm"} and "PDL"->can("srandom")
$INC{"PDL.pm"} "PDL"->can("srandom")
Truth table33%1/3
A and B
A= $INC{"PDL.pm"}B= "PDL"->can("srandom")
ABresult
0X0
100
111
274 7 ▶ Math::Prime::Util::srand($seed) if $INC{'Math/Prime/Util.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"Math/Prime/Util.pm"} 0 7 7
275 }
276  
277 7 ▶ if ( $INC{'Math/Random.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Math/Random.pm"}) 0 7 7
278 0 my $cur_seed = Math::Random::random_get_seed();
279 0 ▶ my $new_seed = ($cur_seed < 1073741781)
Branch: 1 branch
BranchTrueFalseTotal
$cur_seed < 1073741781 ? : 0 0 0
280 ? $cur_seed + ((abs($id) * 10000) % 1073741780)
281 : $cur_seed - ((abs($id) * 10000) % 1073741780);
282  
283 0 Math::Random::random_set_seed($new_seed, $new_seed);
284 }
285  
286 7 ▶ if ( $INC{'Math/Random/MT/Auto.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Math/Random/MT/Auto.pm"}) 0 7 7
287 0 my $cur_seed = Math::Random::MT::Auto::get_seed()->[0];
288 0 ▶ my $new_seed = ($cur_seed < 1073741781)
Branch: 1 branch
BranchTrueFalseTotal
$cur_seed < 1073741781 ? : 0 0 0
289 ? $cur_seed + ((abs($id) * 10000) % 1073741780)
290 : $cur_seed - ((abs($id) * 10000) % 1073741780);
291  
292 0 Math::Random::MT::Auto::set_seed($new_seed);
293 }
294  
295 7 _dispatch($mngd, $func, \@args);
296 }
297 }
298  
299 43 ▶ $MCE::_GMUTEX->unlock() if ( $_tid && $MCE::_GMUTEX );
Branch: 1 branch
BranchTrueFalseTotal
if $_tid and $MCE::_GMUTEX 0 43 43
Condition33%1/3
$_tid and $MCE::_GMUTEX
!ll&&!rl&&r
4300
MC/DC0%0/2
$_tid and $MCE::_GMUTEX
$_tid $MCE::_GMUTEX
Truth table33%1/3
A and B
A= $_tidB= $MCE::_GMUTEX
ABresult
0X0
100
111
300  
301 43 ▶ CORE::kill($killed, $$) if $killed;
Branch: 1 branch
BranchTrueFalseTotal
if $killed 0 43 43
302  
303 43 ▶ return $pid ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$pid ? : 43 0 43
304 }
305  
306 ###############################################################################
307 ## ----------------------------------------------------------------------------
308 ## Public methods.
309 ##
310 ###############################################################################
311  
312 0 ▶sub equal {
Subroutine equal: not called CC=4 SCAR=30.0
Pod documented
313 0 ▶ return 0 unless ( ref $_[0] && ref $_[1] );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] and ref $_[1] 0 0 0
Condition0%0/3
ref $_[0] and ref $_[1]
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and ref $_[1]
ref $_[0] ref $_[1]
Truth table0%0/3
A and B
A= ref $_[0]B= ref $_[1]
ABresult
0X0
100
111
314 0 ▶ $_[0]->{WRK_ID} == $_[1]->{WRK_ID} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'WRK_ID'} == $_[1]{'WRK_ID'} ? : 0 0 0
315 }
316  
317 22 ▶sub error {
Subroutine error: called CC=4 SCAR=15.2
Pod documented
318 22 ▶ _croak('Usage: $child->error()') unless ref( my $self = $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless ref(my $self = $_[0]) 0 22 22
319 22 ▶ $self->join() unless $self->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"REAPED"} 0 22 22
320 22 ▶ $self->{ERROR} || undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"ERROR"} or undef 0 22 22
321 }
322  
323 10 ▶sub exit {
Subroutine exit: called CC=16 SCAR=42.5
Pod documented
324 10 ▶ shift if ( defined $_[0] && $_[0] eq __PACKAGE__ );
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq __PACKAGE__ 0 10 10
Condition33%1/3
defined $_[0] and $_[0] eq __PACKAGE__
!ll&&!rl&&r
0100
MC/DC0%0/2
defined $_[0] and $_[0] eq __PACKAGE__
defined $_[0] $_[0] eq __PACKAGE__
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq __PACKAGE__
ABresult
0X0
100
111
325  
326 10 ▶ my ( $self ) = ( ref $_[0] ? shift : $_SELF );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 10 0 10
327 10 my ( $pkg, $wrk_id ) = ( $self->{PKG}, $self->{WRK_ID} );
328  
329 10 ▶ if ( $wrk_id == $$ && $self->{MGR_ID} eq "$$.$_tid" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wrk_id == $$ and $self->{'MGR_ID'} eq "${$}.$_tid") { } 0 10 10
elsif ($wrk_id == $$) { } 0 10 10
Condition33%1/3
$wrk_id == $$ and $self->{"MGR_ID"} eq "${$}.$_tid"
!ll&&!rl&&r
1000
MC/DC0%0/2
$wrk_id == $$ and $self->{"MGR_ID"} eq "${$}.$_tid"
$wrk_id == $$ $self->{"MGR_ID"} eq "${$}.$_tid"
Truth table33%1/3
A and B
A= $wrk_id == $$B= $self->{"MGR_ID"} eq "${$}.$_tid"
ABresult
0X0
100
111
330 0 MCE::Child->finish('MCE'); CORE::exit(@_);
331 }
332 elsif ( $wrk_id == $$ ) {
333 0 ▶ alarm 0; my ( $exit_status, @res ) = @_; $? = $exit_status || 0;
Condition0%0/2
$exit_status || 0
l!l
00
MC/DC0%0/1
$exit_status || 0
$exit_status
Truth table0%0/2
A
A= $exit_status
Aresult
11
00
334 $_DATA->{$pkg}->set('R'.$wrk_id, @res ? \@res : '')
335 0 ▶ unless $self->{IGNORE};
Branch: 2 branches
BranchTrueFalseTotal
unless $self->{"IGNORE"} 0 0 0
@res ? : 0 0 0
336 0 die "Child exited ($?)\n";
337 0 _exit($?); # not reached
338 }
339  
340 10 ▶ return $self if $self->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"REAPED"} 0 10 10
341  
342 10 ▶ if ( defined $_DATA->{$pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_DATA->{$pkg}) { } 10 0 10
343 10 ▶ sleep $_yield_secs until $_DATA->{$pkg}->exists('S'.$wrk_id);
Branch: 1 branch
BranchTrueFalseTotal
$_DATA->{$pkg}->exists('S' . $wrk_id) or do { &MCE::Child::sleep($_yield_secs) } 10 0 10
344 } else {
345 0 sleep 0.030;
346 }
347  
348 10 ▶ if ($_is_MSWin32) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_is_MSWin32) { } 0 10 10
349 0 ▶ CORE::kill('KILL', $wrk_id) if CORE::kill('ZERO', $wrk_id);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::kill "ZERO", $wrk_id 0 0 0
350 } else {
351 10 ▶ CORE::kill('QUIT', $wrk_id) if CORE::kill('ZERO', $wrk_id);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::kill "ZERO", $wrk_id 10 0 10
352 }
353  
354 10 $self;
355 }
356  
357 19 ▶sub finish {
Subroutine finish: called CC=10 SCAR=24.2
Pod documented
358 19 ▶ _croak('Usage: MCE::Child->finish()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 19 19
359 19 ▶ shift if ( defined $_[0] && $_[0] eq __PACKAGE__ );
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq __PACKAGE__ 19 0 19
Condition33%1/3
defined $_[0] and $_[0] eq __PACKAGE__
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $_[0] and $_[0] eq __PACKAGE__
defined $_[0] $_[0] eq __PACKAGE__
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] eq __PACKAGE__
ABresult
0X0
100
111
360  
361 19 ▶ my $pkg = defined($_[0]) ? shift : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 18 1 19
362  
363 19 ▶ if ( $pkg eq 'MCE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pkg eq 'MCE') { } 17 2 19
elsif (defined $_LIST->{$pkg}) { } 2 0 2
364 17 for my $key ( keys %{ $_LIST } ) { MCE::Child->finish($key); }
365 }
366 elsif ( defined $_LIST->{$pkg} ) {
367 2 ▶ return if $MCE::Signal::KILLED;
Branch: 1 branch
BranchTrueFalseTotal
if $MCE::Signal::KILLED 0 2 2
368  
369 2 ▶ if ( exists $_DELY->{$pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_DELY->{$pkg}) 2 0 2
370 2 &_force_reap($pkg);
371 delete($_DELY->{$pkg}), delete($_DATA->{"$pkg:seed"}),
372 delete($_LIST->{$pkg}), delete($_DATA->{"$pkg:id"}),
373 2 delete($_MNGD->{$pkg}), delete($_DATA->{ $pkg });
374 }
375 }
376  
377 19 @_ = ();
378  
379 19 return;
380 }
381  
382 15 ▶sub is_joinable {
Subroutine is_joinable: called CC=7 SCAR=25.1
Pod documented
383 15 ▶ _croak('Usage: $child->is_joinable()') unless ref( my $self = $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless ref(my $self = $_[0]) 0 15 15
384 15 my ( $wrk_id, $pkg ) = ( $self->{WRK_ID}, $self->{PKG} );
385  
386 15 ▶ if ( $wrk_id == $$ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wrk_id == $$) { } 0 15 15
elsif ($self->{'MGR_ID'} eq "${$}.$_tid") { } 15 0 15
387 0 '';
388 }
389 elsif ( $self->{MGR_ID} eq "$$.$_tid" ) {
390 15 ▶ return '' if $self->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"REAPED"} 0 15 15
391 15 local $!; $_DATA->{$pkg}->reap_data;
392 15 ▶ ( waitpid($wrk_id, _WNOHANG) == 0 ) ? '' : do {
Branch: 1 branch
BranchTrueFalseTotal
waitpid($wrk_id, 1) == 0 ? : 15 0 15
393 0 ▶ _reap_child($self, 0) unless $self->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"REAPED"} 0 0 0
394 0 1;
395 };
396 }
397 else {
398 # limitation for MCE::Child only; allowed for MCE::Hobo
399 0 _croak('Error: $child->is_joinable() not called by managed process');
400 }
401 }
402  
403 15 ▶sub is_running {
Subroutine is_running: called CC=7 SCAR=25.1
Pod documented
404 15 ▶ _croak('Usage: $child->is_running()') unless ref( my $self = $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless ref(my $self = $_[0]) 0 15 15
405 15 my ( $wrk_id, $pkg ) = ( $self->{WRK_ID}, $self->{PKG} );
406  
407 15 ▶ if ( $wrk_id == $$ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wrk_id == $$) { } 0 15 15
elsif ($self->{'MGR_ID'} eq "${$}.$_tid") { } 15 0 15
408 0 1;
409 }
410 elsif ( $self->{MGR_ID} eq "$$.$_tid" ) {
411 15 ▶ return '' if $self->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"REAPED"} 0 15 15
412 15 local $!; $_DATA->{$pkg}->reap_data;
413 15 ▶ ( waitpid($wrk_id, _WNOHANG) == 0 ) ? 1 : do {
Branch: 1 branch
BranchTrueFalseTotal
waitpid($wrk_id, 1) == 0 ? : 15 0 15
414 0 ▶ _reap_child($self, 0) unless $self->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"REAPED"} 0 0 0
415 0 '';
416 };
417 }
418 else {
419 # limitation for MCE::Child only; allowed for MCE::Hobo
420 0 _croak('Error: $child->is_running() not called by managed process');
421 }
422 }
423  
424 33 ▶sub join {
Subroutine join: called CC=12 SCAR=35.9
Pod documented
425 33 ▶ _croak('Usage: $child->join()') unless ref( my $self = $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless ref(my $self = $_[0]) 0 33 33
426 33 my ( $wrk_id, $pkg ) = ( $self->{WRK_ID}, $self->{PKG} );
427  
428 33 ▶ if ( $self->{REAPED} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"REAPED"}) 0 33 33
429 0 ▶ _croak('Child already joined') unless exists( $self->{RESULT} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"RESULT"} 0 0 0
430 0 ▶ $_LIST->{$pkg}->del($wrk_id) if ( defined $_LIST->{$pkg} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $_LIST->{$pkg} 0 0 0
431  
432 return ( defined wantarray )
433 0 ▶ ? wantarray ? @{ delete $self->{RESULT} } : delete( $self->{RESULT} )->[-1]
Branch: 2 branches
BranchTrueFalseTotal
defined wantarray ? : 0 0 0
wantarray ? : 0 0 0
434 : ();
435 }
436  
437 33 ▶ if ( $wrk_id == $$ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wrk_id == $$) { } 0 33 33
elsif ($self->{'MGR_ID'} eq "${$}.$_tid") { } 33 0 33
438 0 _croak('Cannot join self');
439 }
440 elsif ( $self->{MGR_ID} eq "$$.$_tid" ) {
441 # remove from list after reaping
442 33 local $SIG{CHLD};
443 33 _reap_child($self, 1);
444 33 $_LIST->{$pkg}->del($wrk_id);
445 }
446 else {
447 # limitation for MCE::Child only; allowed for MCE::Hobo
448 0 _croak('Error: $child->join() not called by managed process');
449 }
450  
451 33 ▶ return unless ( exists $self->{RESULT} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"RESULT"} 0 33 33
452  
453 ( defined wantarray )
454 0 ▶ ? wantarray ? @{ delete $self->{RESULT} } : delete( $self->{RESULT} )->[-1]
Branch: 2 branches
BranchTrueFalseTotal
defined wantarray ? : 30 3 33
wantarray ? : 0 30 30
455 : ();
456 }
457  
458 5 ▶sub kill {
Subroutine kill: called CC=10 SCAR=29.0
Pod documented
459 5 ▶ _croak('Usage: $child->kill()') unless ref( my $self = $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless ref(my $self = $_[0]) 0 5 5
460 5 my ( $wrk_id, $pkg, $signal ) = ( $self->{WRK_ID}, $self->{PKG}, $_[1] );
461  
462 5 ▶ if ( $wrk_id == $$ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrk_id == $$) 0 5 5
463 0 ▶ CORE::kill($signal || 'INT', $$);
Condition0%0/2
$signal || 'INT'
l!l
00
MC/DC0%0/1
$signal || 'INT'
$signal
Truth table0%0/2
A
A= $signal
Aresult
11
00
464 0 return $self;
465 }
466 5 ▶ if ( $self->{MGR_ID} eq "$$.$_tid" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"MGR_ID"} eq "${$}.$_tid") 5 0 5
467 5 ▶ return $self if $self->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"REAPED"} 0 5 5
468 5 ▶ if ( defined $_DATA->{$pkg} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_DATA->{$pkg}) { } 5 0 5
469 5 ▶ sleep $_yield_secs until $_DATA->{$pkg}->exists('S'.$wrk_id);
Branch: 1 branch
BranchTrueFalseTotal
$_DATA->{$pkg}->exists('S' . $wrk_id) or do { &MCE::Child::sleep($_yield_secs) } 5 0 5
470 } else {
471 0 sleep 0.030;
472 }
473 }
474  
475 5 ▶ CORE::kill($signal || 'INT', $wrk_id) if CORE::kill('ZERO', $wrk_id);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::kill "ZERO", $wrk_id 5 0 5
Condition50%1/2
$signal || 'INT'
l!l
50
MC/DC0%0/1
$signal || 'INT'
$signal
Truth table50%1/2
A
A= $signal
Aresult
11
00
476  
477 5 $self;
478 }
479  
480 5 ▶sub list {
Subroutine list: called CC=3 SCAR=11.7
Pod documented
481 5 ▶ _croak('Usage: MCE::Child->list()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 5 5
482 5 my $pkg = "$$.$_tid.".caller();
483  
484 5 ▶ ( defined $_LIST->{$pkg} ) ? $_LIST->{$pkg}->vals() : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $_LIST->{$pkg} ? : 5 0 5
485 }
486  
487 5 ▶sub list_pids {
Subroutine list_pids: called CC=3 SCAR=11.3
Pod documented
488 5 ▶ _croak('Usage: MCE::Child->list_pids()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 5 5
489 5 my $pkg = "$$.$_tid.".caller(); local $_;
490  
491 5 ▶ ( defined $_LIST->{$pkg} ) ? map { $_->pid } $_LIST->{$pkg}->vals() : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $_LIST->{$pkg} ? : 5 0 5
492 }
493  
494 5 ▶sub list_joinable {
Subroutine list_joinable: called CC=5 SCAR=19.1
Pod documented
495 5 ▶ _croak('Usage: MCE::Child->list_joinable()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 5 5
496 5 my $pkg = "$$.$_tid.".caller();
497  
498 5 ▶ return () unless ( my $list = $_LIST->{$pkg} );
Branch: 1 branch
BranchTrueFalseTotal
unless my $list = $_LIST->{$pkg} 0 5 5
499 5 local ($!, $?, $_); $_DATA->{$pkg}->reap_data;
500  
501 map {
502 5 ▶ ( waitpid($_->{WRK_ID}, _WNOHANG) == 0 ) ? () : do {
Branch: 1 branch
BranchTrueFalseTotal
waitpid($_->{'WRK_ID'}, 1) == 0 ? : 15 0 15
503 0 ▶ _reap_child($_, 0) unless $_->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"REAPED"} 0 0 0
504 0 $_;
505 };
506 }
507 $list->vals();
508 }
509  
510 5 ▶sub list_running {
Subroutine list_running: called CC=5 SCAR=19.1
Pod documented
511 5 ▶ _croak('Usage: MCE::Child->list_running()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 5 5
512 5 my $pkg = "$$.$_tid.".caller();
513  
514 5 ▶ return () unless ( my $list = $_LIST->{$pkg} );
Branch: 1 branch
BranchTrueFalseTotal
unless my $list = $_LIST->{$pkg} 0 5 5
515 5 local ($!, $?, $_); $_DATA->{$pkg}->reap_data;
516  
517 map {
518 5 ▶ ( waitpid($_->{WRK_ID}, _WNOHANG) == 0 ) ? $_ : do {
Branch: 1 branch
BranchTrueFalseTotal
waitpid($_->{'WRK_ID'}, 1) == 0 ? : 15 0 15
519 0 ▶ _reap_child($_, 0) unless $_->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"REAPED"} 0 0 0
520 0 ();
521 };
522 }
523 $list->vals();
524 }
525  
526 17 ▶sub max_workers {
Subroutine max_workers: called CC=5 SCAR=18.4
Pod documented
527 17 ▶ _croak('Usage: MCE::Child->max_workers()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 17 17
528 17 ▶ my $mngd = $_MNGD->{ "$$.$_tid.".caller() } || do {
Condition33%1/3
$$_MNGD{"${$}.$_tid." . (caller())} || do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }
l!l&&r!l&&!r
1700
MC/DC0%0/2
$$_MNGD{"${$}.$_tid." . (caller())} || do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }
$$_MNGD{"${$}.$_tid." . (caller())} do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }
Truth table33%1/3
A || B
A= $$_MNGD{"${$}.$_tid." . (caller())}B= do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }
ABresult
1X1
011
000
529 # construct mngd internally on first use unless defined
530 0 init(); $_MNGD->{ "$$.$_tid.".caller() };
531 };
532 17 ▶ shift if ( $_[0] eq __PACKAGE__ );
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq __PACKAGE__ 17 0 17
533  
534 17 ▶ $mngd->{max_workers} = _max_workers(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 7 10 17
535 17 $mngd->{max_workers};
536 }
537  
538 5 ▶sub pending {
Subroutine pending: called CC=3 SCAR=11.7
Pod documented
539 5 ▶ _croak('Usage: MCE::Child->pending()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 5 5
540 5 my $pkg = "$$.$_tid.".caller();
541  
542 5 ▶ ( defined $_LIST->{$pkg} ) ? $_LIST->{$pkg}->len() : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_LIST->{$pkg} ? : 5 0 5
543 }
544  
545 22 ▶sub pid {
Subroutine pid: called CC=2 SCAR=7.6
Pod documented
546 22 ▶ ref($_[0]) ? $_[0]->{WRK_ID} : $_SELF->{WRK_ID};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 22 0 22
547 }
548  
549 7 ▶sub result {
Subroutine result: called CC=5 SCAR=18.6
Pod documented
550 7 ▶ _croak('Usage: $child->result()') unless ref( my $self = $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless ref(my $self = $_[0]) 0 7 7
551 7 ▶ return $self->join() unless $self->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"REAPED"} 0 7 7
552  
553 7 ▶ _croak('Child already joined') unless exists( $self->{RESULT} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"RESULT"} 0 7 7
554 0 ▶ wantarray ? @{ delete $self->{RESULT} } : delete( $self->{RESULT} )->[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
555 }
556  
557 0 ▶sub seed {
Subroutine seed: not called CC=3 SCAR=24.8
Pod documented
558 0 ▶ _croak('Usage: MCE::Child->seed()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
559 0 ▶ my $pkg = exists $_SELF->{PKG} ? $_SELF->{PKG} : "$$.$_tid.".caller();
Branch: 1 branch
BranchTrueFalseTotal
exists $_SELF->{'PKG'} ? : 0 0 0
560  
561 0 return $_DATA->{"$pkg:seed"};
562 }
563  
564 0 ▶sub self {
Subroutine self: not called CC=2 SCAR=17.9
Pod documented
565 0 ▶ ref($_[0]) ? $_[0] : $_SELF;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
566 }
567  
568 1 ▶sub wait_all {
Subroutine wait_all: called CC=6 SCAR=22.3
Pod documented
569 1 ▶ _croak('Usage: MCE::Child->wait_all()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 1 1
570 1 my $pkg = "$$.$_tid.".caller();
571  
572 return wantarray ? () : 0
573 1 ▶ if ( !defined $_LIST->{$pkg} || !$_LIST->{$pkg}->len() );
Branch: 2 branches
BranchTrueFalseTotal
unless defined $_LIST->{$pkg} and $_LIST->{$pkg}->len 0 1 1
wantarray ? : 0 0 0
Condition33%1/3
defined $_LIST->{$pkg} and $_LIST->{$pkg}->len
!ll&&!rl&&r
001
MC/DC0%0/2
defined $_LIST->{$pkg} and $_LIST->{$pkg}->len
defined $_LIST->{$pkg} $_LIST->{$pkg}->len
Truth table33%1/3
A and B
A= defined $_LIST->{$pkg}B= $_LIST->{$pkg}->len
ABresult
0X0
100
111
574  
575 1 local $_; ( wantarray )
576 0 ? map { $_->join(); $_ } $_LIST->{$pkg}->vals()
577 1 ▶ : map { $_->join(); () } $_LIST->{$pkg}->vals();
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
578 }
579  
580 9 *waitall = \&wait_all; # compatibility
581  
582 4 ▶sub wait_one {
Subroutine wait_one: called CC=4 SCAR=15.6
Pod documented
583 4 ▶ _croak('Usage: MCE::Child->wait_one()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 4 4
584 4 my $pkg = "$$.$_tid.".caller();
585  
586 return undef
587 4 ▶ if ( !defined $_LIST->{$pkg} || !$_LIST->{$pkg}->len() );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_LIST->{$pkg} and $_LIST->{$pkg}->len 0 4 4
Condition33%1/3
defined $_LIST->{$pkg} and $_LIST->{$pkg}->len
!ll&&!rl&&r
004
MC/DC0%0/2
defined $_LIST->{$pkg} and $_LIST->{$pkg}->len
defined $_LIST->{$pkg} $_LIST->{$pkg}->len
Truth table33%1/3
A and B
A= defined $_LIST->{$pkg}B= $_LIST->{$pkg}->len
ABresult
0X0
100
111
588  
589 4 _wait_one($pkg);
590 }
591  
592 9 *waitone = \&wait_one; # compatibility
593  
594 0 ▶sub yield {
Subroutine yield: not called CC=7 SCAR=40.3
Pod documented
595 0 ▶ _croak('Usage: MCE::Child->yield()') if ref($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
596 0 ▶ shift if ( defined $_[0] && $_[0] eq __PACKAGE__ );
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[0] eq __PACKAGE__ 0 0 0
Condition0%0/3
defined $_[0] and $_[0] eq __PACKAGE__
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and $_[0] eq __PACKAGE__
defined $_[0] $_[0] eq __PACKAGE__
Truth table0%0/3
A and B
A= defined $_[0]B= $_[0] eq __PACKAGE__
ABresult
0X0
100
111
597  
598 0 ▶ my $pkg = $_SELF->{PKG} || do {
Condition0%0/3
$_SELF->{'PKG'} || do { my $mngd = $$_MNGD{"${$}.$_tid." . (caller())} || do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }; $mngd->{'PKG'} }
l!l&&r!l&&!r
000
MC/DC0%0/2
$_SELF->{'PKG'} || do { my $mngd = $$_MNGD{"${$}.$_tid." . (caller())} || do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }; $mngd->{'PKG'} }
$_SELF->{'PKG'} do { my $mngd = $$_MNGD{"${$}.$_tid." . (caller())} || do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }; $mngd->{'PKG'} }
Truth table0%0/3
A || B
A= $_SELF->{'PKG'}B= do { my $mngd = $$_MNGD{"${$}.$_tid." . (caller())} || do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }; $mngd->{'PKG'} }
ABresult
1X1
011
000
599 0 ▶ my $mngd = $_MNGD->{ "$$.$_tid.".caller() } || do {
Condition0%0/3
$$_MNGD{"${$}.$_tid." . (caller())} || do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }
l!l&&r!l&&!r
000
MC/DC0%0/2
$$_MNGD{"${$}.$_tid." . (caller())} || do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }
$$_MNGD{"${$}.$_tid." . (caller())} do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }
Truth table0%0/3
A || B
A= $$_MNGD{"${$}.$_tid." . (caller())}B= do { init(); $$_MNGD{"${$}.$_tid." . (caller())} }
ABresult
1X1
011
000
600 # construct mngd internally on first use unless defined
601 0 init(); $_MNGD->{ "$$.$_tid.".caller() };
602 };
603 0 $mngd->{PKG};
604 };
605  
606 0 ▶ return unless $_DELY->{$pkg};
Branch: 1 branch
BranchTrueFalseTotal
unless $_DELY->{$pkg} 0 0 0
607 0 my $seconds = $_DELY->{$pkg}->seconds(@_);
608  
609 0 MCE::Util::_sleep( $seconds );
610 }
611  
612 ###############################################################################
613 ## ----------------------------------------------------------------------------
614 ## Private methods.
615 ##
616 ###############################################################################
617  
618 0 ▶sub _croak {
Subroutine _croak: not called CC=2 SCAR=17.9
619 0 ▶ if ( $INC{'MCE.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{'MCE.pm'}) { } 0 0 0
620 0 goto &MCE::_croak;
621 }
622 else {
623 0 $SIG{__DIE__} = \&MCE::Signal::_die_handler;
624 0 $SIG{__WARN__} = \&MCE::Signal::_warn_handler;
625  
626 0 $\ = undef; goto &Carp::croak;
627 }
628 }
629  
630 7 ▶sub _dispatch {
Subroutine _dispatch: called CC=20 SCAR=42.2
631 7 my ( $mngd, $func, $args ) = @_;
632  
633 7 $mngd->{WRK_ID} = $_SELF->{WRK_ID} = $$, $? = 0;
634 7 ▶ $ENV{PERL_MCE_IPC} = 'win32' if $_is_MSWin32;
Branch: 1 branch
BranchTrueFalseTotal
if $_is_MSWin32 0 7 7
635  
636 {
637 7 local $!;
638 7 ▶ (*STDERR)->autoflush(1) if defined( fileno *STDERR );
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDERR 7 0 7
639 7 ▶ (*STDOUT)->autoflush(1) if defined( fileno *STDOUT );
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDOUT 7 0 7
640 }
641  
642 # Run task.
643 my $child_timeout = ( exists $_SELF->{child_timeout} )
644 7 ▶ ? $_SELF->{child_timeout} : $mngd->{child_timeout};
Branch: 1 branch
BranchTrueFalseTotal
exists $_SELF->{'child_timeout'} ? : 0 7 7
645  
646 my $void_context = ( exists $_SELF->{void_context} )
647 7 ▶ ? $_SELF->{void_context} : $mngd->{void_context};
Branch: 1 branch
BranchTrueFalseTotal
exists $_SELF->{'void_context'} ? : 0 7 7
648  
649 7 my @res; my $timed_out = 0;
650  
651 0 ▶ local $SIG{'ALRM'} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
652 0 ▶ alarm 0; $timed_out = 1; $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
653 0 die "Child timed out\n";
654 7 };
655  
656 7 ▶ if ( $void_context || $_SELF->{IGNORE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($void_context or $_SELF->{'IGNORE'}) { } 0 7 7
Condition33%1/3
$void_context or $_SELF->{"IGNORE"}
l!l&&r!l&&!r
007
MC/DC0%0/2
$void_context or $_SELF->{"IGNORE"}
$void_context $_SELF->{"IGNORE"}
Truth table33%1/3
A or B
A= $void_contextB= $_SELF->{"IGNORE"}
ABresult
1X1
011
000
657 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
658 0 ▶ eval { alarm($child_timeout || 0); $func->(@{ $args }) };
Condition0%0/2
$child_timeout || 0
l!l
00
MC/DC0%0/1
$child_timeout || 0
$child_timeout
Truth table0%0/2
A
A= $child_timeout
Aresult
11
00
659 }
660 else {
661 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
662 7 ▶ @res = eval { alarm($child_timeout || 0); $func->(@{ $args }) };
Condition50%1/2
$child_timeout || 0
l!l
07
MC/DC0%0/1
$child_timeout || 0
$child_timeout
Truth table50%1/2
A
A= $child_timeout
Aresult
11
00
663 }
664  
665 7 alarm 0;
666 7 ▶ $@ = "Child timed out" if $timed_out;
Branch: 1 branch
BranchTrueFalseTotal
if $timed_out 0 7 7
667  
668 7 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 7 7
669 0 ▶ _exit($?) if ( $@ =~ /^Child exited \(\S+\)$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /^Child exited \(\S+\)$/ 0 0 0
670 0 my $err = $@; $? = 1; $err =~ s/, <__ANONIO__> line \d+//;
671  
672 0 ▶ if ( ! $_SELF->{IGNORE} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_SELF->{"IGNORE"}) 0 0 0
673 $_DATA->{ $_SELF->{PKG} }->set('S'.$$, $err),
674 0 $_DATA->{ $_SELF->{PKG} }->set('R'.$$, '');
675 }
676  
677 0 ▶ if ( !$timed_out && !$mngd->{on_finish} && !$INC{'MCE/Simple.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($timed_out or $mngd->{"on_finish"} or $INC{"MCE/Simple.pm"}) 0 0 0
Condition0%0/6
$timed_out or $mngd->{"on_finish"} or $INC{"MCE/Simple.pm"}
l!l&&r!l&&!r
000
$timed_out or $mngd->{"on_finish"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$timed_out or $mngd->{"on_finish"} or $INC{"MCE/Simple.pm"}
$timed_out $mngd->{"on_finish"} $INC{"MCE/Simple.pm"}
Truth table0%0/4
A or B or C
A= $timed_outB= $mngd->{"on_finish"}C= $INC{"MCE/Simple.pm"}
ABCresult
1XX1
01X1
0011
0000
678 0 ▶ use bytes; warn "Child $$ terminated abnormally: reason $err\n";
Subroutine BEGIN: called CC=1 SCAR=0.2
679 }
680 }
681 else {
682 7 ▶ shift(@res) if ref($res[0]) =~ /^MCE::(?:Barrier|Semaphore)::_guard/s;
Branch: 1 branch
BranchTrueFalseTotal
if ref($res[0]) =~ /^MCE::(?:Barrier|Semaphore)::_guard/s 0 7 7
683 $_DATA->{ $_SELF->{PKG} }->set('R'.$$, @res ? \@res : '')
684 7 ▶ if ( ! $_SELF->{IGNORE} );
Branch: 2 branches
BranchTrueFalseTotal
unless $_SELF->{"IGNORE"} 7 0 7
@res ? : 7 0 7
685 }
686  
687 7 _exit($?);
688 }
689  
690 7 ▶sub _exit {
Subroutine _exit: called CC=12 SCAR=34.0
691 7 my ( $exit_status ) = @_;
692  
693 # Check for nested workers not yet joined.
694 7 ▶ MCE::Child->finish('MCE') if ( !$_SELF->{SIGNALED} && keys %{ $_LIST } );
Branch: 1 branch
BranchTrueFalseTotal
if not $_SELF->{"SIGNALED"} and keys %{$_LIST;} 0 7 7
Condition33%1/3
not $_SELF->{"SIGNALED"} and keys %{$_LIST;}
!ll&&!rl&&r
070
MC/DC0%0/2
not $_SELF->{"SIGNALED"} and keys %{$_LIST;}
not $_SELF->{"SIGNALED"} keys %{$_LIST;}
Truth table33%1/3
not(A) and B
A= not $_SELF->{"SIGNALED"}B= keys %{$_LIST;}
ABresult
0X0
100
111
695  
696 # Exit child process.
697 7 ▶ $SIG{__DIE__} = sub {} unless $_tid;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $_tid 7 0 7
698 7 ▶ $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
699  
700 7 ▶ threads->exit($exit_status) if ( $INC{'threads.pm'} && $_is_MSWin32 );
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} and $_is_MSWin32 0 7 7
Condition33%1/3
$INC{"threads.pm"} and $_is_MSWin32
!ll&&!rl&&r
700
MC/DC0%0/2
$INC{"threads.pm"} and $_is_MSWin32
$INC{"threads.pm"} $_is_MSWin32
Truth table33%1/3
A and B
A= $INC{"threads.pm"}B= $_is_MSWin32
ABresult
0X0
100
111
701 7 ▶ CORE::kill('KILL', $$) if ( $_SELF->{SIGNALED} && !$_is_MSWin32 );
Branch: 1 branch
BranchTrueFalseTotal
if $_SELF->{"SIGNALED"} and not $_is_MSWin32 0 7 7
Condition33%1/3
$_SELF->{"SIGNALED"} and not $_is_MSWin32
!ll&&!rl&&r
700
MC/DC0%0/2
$_SELF->{"SIGNALED"} and not $_is_MSWin32
$_SELF->{"SIGNALED"} not $_is_MSWin32
Truth table33%1/3
A and not(B)
A= $_SELF->{"SIGNALED"}B= not $_is_MSWin32
ABresult
0X0
100
111
702  
703 my $posix_exit = ( exists $_SELF->{posix_exit} )
704 7 ▶ ? $_SELF->{posix_exit} : $_MNGD->{ $_SELF->{PKG} }{posix_exit};
Branch: 1 branch
BranchTrueFalseTotal
exists $_SELF->{'posix_exit'} ? : 0 7 7
705  
706 7 ▶ if ( $posix_exit && !$_is_MSWin32 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($posix_exit and not $_is_MSWin32) 0 7 7
Condition33%1/3
$posix_exit and not $_is_MSWin32
!ll&&!rl&&r
700
MC/DC0%0/2
$posix_exit and not $_is_MSWin32
$posix_exit not $_is_MSWin32
Truth table33%1/3
A and not(B)
A= $posix_exitB= not $_is_MSWin32
ABresult
0X0
100
111
707 0 eval { MCE::Mutex::Channel::_destroy() };
708 0 ▶ POSIX::_exit($exit_status) if $INC{'POSIX.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"POSIX.pm"} 0 0 0
709 0 CORE::kill('KILL', $$);
710 }
711  
712 7 CORE::exit($exit_status);
713 }
714  
715 9 ▶sub _force_reap {
Subroutine _force_reap: called CC=9 SCAR=40.6
716 9 my ( $count, $pkg ) = ( 0, @_ );
717 9 ▶ return unless ( defined $_LIST->{$pkg} && $_LIST->{$pkg}->len() );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_LIST->{$pkg} and $_LIST->{$pkg}->len 9 0 9
Condition33%1/3
defined $_LIST->{$pkg} and $_LIST->{$pkg}->len
!ll&&!rl&&r
090
MC/DC0%0/2
defined $_LIST->{$pkg} and $_LIST->{$pkg}->len
defined $_LIST->{$pkg} $_LIST->{$pkg}->len
Truth table33%1/3
A and B
A= defined $_LIST->{$pkg}B= $_LIST->{$pkg}->len
ABresult
0X0
100
111
718  
719 0 for my $child ( $_LIST->{$pkg}->vals() ) {
720 0 ▶ next if $child->{IGNORE};
Branch: 1 branch
BranchTrueFalseTotal
if $child->{"IGNORE"} 0 0 0
721  
722 0 ▶ if ( $child->is_running() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child->is_running) 0 0 0
723 0 ▶ sleep($_yield_secs), CORE::kill('KILL', $child->pid())
Branch: 1 branch
BranchTrueFalseTotal
if CORE::kill "ZERO", $child->pid 0 0 0
724 if CORE::kill('ZERO', $child->pid());
725 0 $count++;
726 }
727 }
728  
729 0 $_LIST->{$pkg}->clear();
730  
731 0 ▶ warn "Finished with active child processes [$pkg] ($count)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $count and not $_is_MSWin32 0 0 0
Condition0%0/3
$count and not $_is_MSWin32
!ll&&!rl&&r
000
MC/DC0%0/2
$count and not $_is_MSWin32
$count not $_is_MSWin32
Truth table0%0/3
A and not(B)
A= $countB= not $_is_MSWin32
ABresult
0X0
100
111
732 if ( $count && !$_is_MSWin32 );
733  
734 0 return;
735 }
736  
737 0 ▶sub _quit {
Subroutine _quit: not called CC=4 SCAR=30.0
738 0 ▶ return MCE::Signal::defer($_[0]) if $MCE::Signal::IPC;
Branch: 1 branch
BranchTrueFalseTotal
if $MCE::Signal::IPC 0 0 0
739  
740 0 alarm 0; my ( $name ) = @_;
741 0 $_SELF->{SIGNALED} = 1, $name =~ s/^SIG//;
742  
743 0 ▶ $SIG{$name} = sub {}, CORE::kill($name, -$$)
Subroutine __ANON__: not called CC=1 SCAR=0.0
744 0 ▶ if ( exists $SIG{$name} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $SIG{$name} 0 0 0
745  
746 0 ▶ if ( ! $_SELF->{IGNORE} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_SELF->{"IGNORE"}) 0 0 0
747 0 my ( $pkg, $wrk_id ) = ( $_SELF->{PKG}, $_SELF->{WRK_ID} );
748 0 $_DATA->{$pkg}->set('R'.$wrk_id, '');
749 }
750  
751 0 _exit(0);
752 }
753  
754 37 ▶sub _reap_child {
Subroutine _reap_child: called CC=15 SCAR=37.6
755 37 my ( $child, $wait_flag ) = @_;
756 37 ▶ return if ( !$child || !defined $child->{PKG} );
Branch: 1 branch
BranchTrueFalseTotal
unless $child and defined $child->{"PKG"} 0 37 37
Condition33%1/3
$child and defined $child->{"PKG"}
!ll&&!rl&&r
0037
MC/DC0%0/2
$child and defined $child->{"PKG"}
$child defined $child->{"PKG"}
Truth table33%1/3
A and B
A= $childB= defined $child->{"PKG"}
ABresult
0X0
100
111
757  
758 37 local @_ = $_DATA->{ $child->{PKG} }->get($child->{WRK_ID}, $wait_flag);
759  
760 37 ▶ ( $child->{ERROR}, $child->{RESULT}, $child->{REAPED} ) =
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] ? : 22 15 37
Condition50%1/2
pop() || ''
l!l
037
MC/DC0%0/1
pop() || ''
pop()
Truth table50%1/2
A
A= pop()
Aresult
11
00
761 ( pop || '', length $_[0] ? pop : [], 1 );
762  
763 37 ▶ return if $child->{IGNORE};
Branch: 1 branch
BranchTrueFalseTotal
if $child->{"IGNORE"} 0 37 37
764  
765 37 ▶ my ( $exit, $err ) = ( $? || 0, $child->{ERROR} );
Condition100%2/2
$? || 0
l!l
1522
MC/DC100%1/1
$? || 0
$?
Truth table100%2/2
A
A= $?
Aresult
11
00
766 37 my ( $code, $sig ) = ( $exit >> 8, $exit & 0x7f );
767  
768 37 ▶ if ( $code > 100 && !$err ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code > 100 and not $err) 0 37 37
Condition33%1/3
$code > 100 and not $err
!ll&&!rl&&r
3700
MC/DC0%0/2
$code > 100 and not $err
$code > 100 not $err
Truth table33%1/3
A and not(B)
A= $code > 100B= not $err
ABresult
0X0
100
111
769 0 ▶ $code = 2, $sig = 1, $err = 'Child received SIGHUP' if $code == 101;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 101 0 0 0
770 0 ▶ $code = 2, $sig = 2, $err = 'Child received SIGINT' if $code == 102;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 102 0 0 0
771 0 ▶ $code = 2, $sig = 6, $err = 'Child received SIGABRT' if $code == 106;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 106 0 0 0
772 0 ▶ $code = 2, $sig = 11, $err = 'Child received SIGSEGV' if $code == 111;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 111 0 0 0
773 0 ▶ $code = 2, $sig = 15, $err = 'Child received SIGTERM' if $code == 115;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 115 0 0 0
774  
775 0 $child->{ERROR} = $err;
776 }
777  
778 37 ▶ if ( my $on_finish = $_MNGD->{ $child->{PKG} }{on_finish} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $on_finish = $$_MNGD{$child->{"PKG"}}{"on_finish"}) 7 30 37
779 $on_finish->(
780 $child->{WRK_ID}, $code, $child->{ident}, $sig, $err,
781 7 @{ $child->{RESULT} }
782 );
783 }
784  
785 37 return;
786 }
787  
788 0 ▶sub _trap {
Subroutine _trap: not called CC=9 SCAR=45.0
789 0 ▶ return MCE::Signal::defer($_[0]) if $MCE::Signal::IPC;
Branch: 1 branch
BranchTrueFalseTotal
if $MCE::Signal::IPC 0 0 0
790  
791 0 alarm 0; my ( $exit_status, $name ) = ( 2, @_ );
792 0 $_SELF->{SIGNALED} = 1, $name =~ s/^SIG//;
793  
794 0 ▶ $SIG{$name} = sub {}, CORE::kill($name, -$$)
Subroutine __ANON__: not called CC=1 SCAR=0.0
795 0 ▶ if ( exists $SIG{$name} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $SIG{$name} 0 0 0
796  
797 0 ▶ if ( $name eq 'HUP' ) { $exit_status = 101 }
Branch: 5 branches
BranchTrueFalseTotal
if ($name eq 'HUP') { } 0 0 0
elsif ($name eq 'INT') { } 0 0 0
elsif ($name eq 'ABRT') { } 0 0 0
elsif ($name eq 'SEGV') { } 0 0 0
elsif ($name eq 'TERM') { } 0 0 0
798 0 elsif ( $name eq 'INT' ) { $exit_status = 102 }
799 0 elsif ( $name eq 'ABRT' ) { $exit_status = 106 }
800 0 elsif ( $name eq 'SEGV' ) { $exit_status = 111 }
801 0 elsif ( $name eq 'TERM' ) { $exit_status = 115 }
802  
803 0 ▶ if ( ! $_SELF->{IGNORE} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_SELF->{"IGNORE"}) 0 0 0
804 0 my ( $pkg, $wrk_id ) = ( $_SELF->{PKG}, $_SELF->{WRK_ID} );
805 0 $_DATA->{$pkg}->set('R'.$wrk_id, '');
806 }
807  
808 0 _exit($exit_status);
809 }
810  
811 4 ▶sub _wait_one {
Subroutine _wait_one: called CC=5 SCAR=16.1
812 4 my ( $pkg ) = @_;
813 4 my ( $list, $self, $wrk_id ) = ( $_LIST->{$pkg} ); local $!;
814  
815 4 while () {
816 480 $_DATA->{$pkg}->reap_data;
817 480 for my $child ( $list->vals() ) {
818 480 $wrk_id = $child->{WRK_ID};
819 480 ▶ return $list->del($wrk_id) if $child->{REAPED};
Branch: 1 branch
BranchTrueFalseTotal
if $child->{"REAPED"} 0 480 480
820 480 ▶ $self = $list->del($wrk_id), last if waitpid($wrk_id, _WNOHANG);
Branch: 1 branch
BranchTrueFalseTotal
if waitpid $wrk_id, 1 4 476 480
821 }
822 480 ▶ last if $self;
Branch: 1 branch
BranchTrueFalseTotal
if $self 4 476 480
823 476 sleep $_yield_secs;
824 }
825  
826 4 _reap_child($self, 0);
827  
828 4 $self;
829 }
830  
831 ###############################################################################
832 ## ----------------------------------------------------------------------------
833 ## Delay implementation suited for MCE::Child.
834 ##
835 ###############################################################################
836  
837 package # hide from rpm
838 MCE::Child::_delay;
839  
840 9 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
841 9 my ( $class, $chnl, $delay ) = @_;
842  
843 9 ▶ if ( !defined $delay ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $delay) 9 0 9
844 9 ▶ $delay = ($^O =~ /mswin|mingw|msys|cygwin/i) ? 0.015 : 0.008;
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /mswin|mingw|msys|cygwin/i ? : 0 9 9
845 }
846  
847 9 $chnl->send(undef);
848  
849 9 bless [ $delay, $chnl ], $class;
850 }
851  
852 0 ▶sub seconds {
Subroutine seconds: not called CC=5 SCAR=34.0
853 0 my ( $self, $how_long ) = @_;
854 0 ▶ my $delay = defined($how_long) ? $how_long : $self->[0];
Branch: 1 branch
BranchTrueFalseTotal
defined $how_long ? : 0 0 0
855 0 my $lapse = $self->[1]->recv();
856 0 my $time = MCE::Util::_time();
857  
858 0 ▶ if ( !$delay || !defined $lapse ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $delay && defined $lapse) { } 0 0 0
elsif ($lapse + $delay - $time < 0) { } 0 0 0
Condition0%0/3
$delay && defined $lapse
!ll&&!rl&&r
000
MC/DC0%0/2
$delay && defined $lapse
$delay defined $lapse
Truth table0%0/3
A && B
A= $delayB= defined $lapse
ABresult
0X0
100
111
859 0 $lapse = $time;
860 }
861 elsif ( $lapse + $delay - $time < 0 ) {
862 0 $lapse += int( abs($time - $lapse) / $delay + 0.5 ) * $delay;
863 }
864  
865 0 $self->[1]->send( $lapse += $delay );
866  
867 0 return $lapse - $time;
868 }
869  
870 ###############################################################################
871 ## ----------------------------------------------------------------------------
872 ## Hash and ordhash implementations suited for MCE::Child.
873 ##
874 ###############################################################################
875  
876 package # hide from rpm
877 MCE::Child::_hash;
878  
879 9 ▶use Time::HiRes 'sleep';
Subroutine BEGIN: called CC=1 SCAR=0.0
880  
881 9 ▶use constant {
Subroutine BEGIN: called CC=3 SCAR=11.7
882 9 ▶ _WNOHANG => ( $INC{'POSIX.pm'} )
Branch: 2 branches
BranchTrueFalseTotal
$INC{'POSIX.pm'} ? : 0 9 9
$^O eq 'solaris' ? : 0 9 9
883 ? &POSIX::WNOHANG : ( $^O eq 'solaris' ) ? 64 : 1
884 9 };
885  
886 9 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
887 9 my ( $class, $chnl ) = @_;
888 9 bless [ {}, $chnl ], shift;
889 }
890  
891 7 ▶sub clear {
Subroutine clear: called CC=2 SCAR=7.0
892 7 my ( $self ) = @_;
893 7 ▶ 1 while ( $self->[1]->recv2_nb() );
Branch: 1 branch
BranchTrueFalseTotal
$self->[1]->recv2_nb and do { '???' } 0 7 7
894 7 %{ $self->[0] } = ();
895 }
896  
897 15 ▶sub exists {
Subroutine exists: called CC=1 SCAR=0.0
898 15 my ( $self, $key ) = @_;
899 15 $self->reap_data;
900 15 CORE::exists $self->[0]{ $key };
901 }
902  
903 50 ▶sub get_done {
Subroutine get_done: called CC=3 SCAR=11.0
904 50 my ( $self ) = @_;
905 50 my @ret;
906  
907 50 $self->reap_data;
908 50 for my $key (keys %{ $self->[0] }) {
909 13 ▶ push @ret, $key if ( substr($key, 0, 1) eq 'R' );
Branch: 1 branch
BranchTrueFalseTotal
if substr($key, 0, 1) eq "R" 0 13 13
910 }
911  
912 50 return @ret;
913 }
914  
915 37 ▶sub get {
Subroutine get: called CC=10 SCAR=23.3
916 37 my ( $self, $wrk_id, $wait_flag ) = @_;
917 37 ▶ $self->reap_data if ( !CORE::exists $self->[0]{ 'R'.$wrk_id } );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->[0]{'R' . $wrk_id} 22 15 37
918  
919 37 ▶ if ( $wait_flag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wait_flag) 33 4 37
920 33 local $!;
921 33 ▶ ( CORE::exists $self->[0]{ 'R'.$wrk_id } ) ? waitpid($wrk_id, 0) : do {
Branch: 1 branch
BranchTrueFalseTotal
exists $self->[0]{'R' . $wrk_id} ? : 23 10 33
922 10 while () {
923 20 my $data = $self->[1]->recv2_nb();
924 20 ▶ if ( !defined $data ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 10 10 20
925 10 ▶ last if waitpid($wrk_id, _WNOHANG);
Branch: 1 branch
BranchTrueFalseTotal
if waitpid $wrk_id, 1 0 10 10
926 10 sleep(0.0009), next;
927 }
928 10 $self->[0]{ $data->[0] } = $data->[1];
929 10 ▶ waitpid($wrk_id, 0), last if $data->[0] eq 'R'.$wrk_id;
Branch: 1 branch
BranchTrueFalseTotal
if $data->[0] eq 'R' . $wrk_id 10 0 10
930 }
931 10 ▶ $self->reap_data if ( !CORE::exists $self->[0]{ 'R'.$wrk_id } );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->[0]{'R' . $wrk_id} 0 10 10
932 };
933 }
934  
935 37 my $result = delete $self->[0]{ 'R'.$wrk_id };
936 37 my $error = delete $self->[0]{ 'S'.$wrk_id };
937  
938 37 ▶ $result = '' unless ( defined $result );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 37 37
939 37 ▶ $error = '' unless ( defined $error );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error 0 37 37
940  
941 37 return ( $result, $error );
942 }
943  
944 607 ▶sub reap_data {
Subroutine reap_data: called CC=2 SCAR=6.9
945 607 my ( $self ) = @_;
946  
947 607 ▶ while ( my $data = $self->[1]->recv2_nb() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->[1]->recv2_nb) 66 607 673
948 66 $self->[0]{ $data->[0] } = $data->[1];
949 }
950  
951 607 return;
952 }
953  
954 14 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
955 14 $_[0]->[1]->send2([ $_[1], $_[2] ]);
956 }
957  
958 package # hide from rpm
959 MCE::Child::_ordhash;
960  
961 9 ▶sub new { bless [ {}, [], {}, 0 ], shift; } # data, keys, indx, gcnt
Subroutine new: called CC=1 SCAR=0.0
962 0 ▶sub exists { CORE::exists $_[0]->[0]{ $_[1] }; }
Subroutine exists: not called CC=1 SCAR=6.9
963 0 ▶sub get { $_[0]->[0]{ $_[1] }; }
Subroutine get: not called CC=1 SCAR=6.9
964 19 ▶sub len { scalar keys %{ $_[0]->[0] }; }
Subroutine len: called CC=1 SCAR=0.0
965  
966 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
967 0 my ( $self ) = @_;
968 0 %{ $self->[0] } = @{ $self->[1] } = %{ $self->[2] } = (), $self->[3] = 0;
969  
970 0 return;
971 }
972  
973 37 ▶sub del {
Subroutine del: called CC=5 SCAR=16.1
974 37 my ( $self, $key ) = @_;
975 37 ▶ return undef unless defined( my $off = delete $self->[2]{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $off = delete $self->[2]{$key}) 0 37 37
976  
977 # tombstone
978 37 $self->[1][$off] = undef;
979  
980 # GC keys and refresh index
981 37 ▶ if ( ++$self->[3] > @{ $self->[1] } * 0.667 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->[3] > @{$self->[1];} * "0.667") 15 22 37
982 15 my ( $keys, $indx ) = ( $self->[1], $self->[2] );
983 15 my $i; $i = $self->[3] = 0;
984 15 for my $k ( @{ $keys } ) {
985 37 ▶ $keys->[$i] = $k, $indx->{$k} = $i++ if defined($k);
Branch: 1 branch
BranchTrueFalseTotal
if defined $k 0 37 37
986 }
987 15 splice @{ $keys }, $i;
988 }
989  
990 37 delete $self->[0]{$key};
991 }
992  
993 43 ▶sub set {
Subroutine set: called CC=2 SCAR=7.0
994 43 my ( $self, $key ) = @_;
995 43 ▶ $self->[0]{$key} = $_[2], return 1 if exists($self->[0]{$key});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->[0]{$key} 0 43 43
996  
997 43 $self->[2]{$key} = @{ $self->[1] }; push @{ $self->[1] }, $key;
998 43 $self->[0]{$key} = $_[2];
999  
1000 43 return 1;
1001 }
1002  
1003 501 ▶sub vals {
Subroutine vals: called CC=2 SCAR=7.9
1004 501 my ( $self ) = @_;
1005 $self->[3]
1006 0 ? @{ $self->[0] }{ grep defined($_), @{ $self->[1] } }
1007 501 ▶ : @{ $self->[0] }{ @{ $self->[1] } };
Branch: 1 branch
BranchTrueFalseTotal
$self->[3] ? : 0 501 501
1008 }
1009  
1010 9 1;
1011  
1012 __END__
« MCE/Channel/ThreadsFast.pm ↑ Summary MCE/Channel/Threads.pm »