Hobo.pm

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