Hobo.pm

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