MCE/Core/Worker.pm

filter: Statementstmt 59.7% 226 / 378 Branchbran 38.8% 104 / 268 Conditioncond 18.1% 12 / 66 MC/DCmcdc 0.0% 0 / 38 Subroutinesub 53.8% 14 / 26 Podpod n/a totaltotal 45.8% 356 / 776 CC 157 SCAR 44.3
CC
157
Cov
48%
_do_user_func
259.6
_worker_do
112.1
__ANON__
110.0
CRAP 84.3
« MCE/Core/Input/Iterator.pm ↑ Summary MCE/Step.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Core methods for the worker process.
4 ##
5 ## This package provides main, loop, and relevant methods used internally by
6 ## the worker process.
7 ##
8 ## There is no public API.
9 ##
10 ###############################################################################
11  
12 package MCE::Core::Worker;
13  
14 94 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 94 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 94 our $VERSION = '1.904';
18  
19 94 ▶my $_tid = $INC{'threads.pm'} ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 94 94
20  
21 0 ▶sub CLONE {
Subroutine CLONE: not called CC=2 SCAR=17.9
22 0 ▶ $_tid = threads->tid() if $INC{'threads.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 0 0
23 }
24  
25 ## Items below are folded into MCE.
26  
27 package # hide from rpm
28 MCE;
29  
30 94 ▶no warnings qw( bareword threads recursion uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 ###############################################################################
33 ## ----------------------------------------------------------------------------
34 ## Internal do, gather and send related functions for serializing data to
35 ## destination. User functions for handling gather, queue or void.
36 ##
37 ###############################################################################
38  
39 {
40 my (
41 94 $_dest, $_len, $_tag, $_task_id, $_user_func, $_val, $_wa,
42 $_DAT_LOCK, $_DAT_W_SOCK, $_DAU_W_SOCK, $_chn, $_lock_chn,
43 $_dat_ex, $_dat_un
44 );
45  
46 94 ▶ my $_is_MSWin32 = ($^O eq 'MSWin32') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 94 94
47  
48 ## Create array structure containing various send functions.
49 94 my @_dest_function = ();
50  
51 0 ▶ $_dest_function[SENDTO_FILEV2] = sub { ## Content >> File
Subroutine __ANON__: not called CC=6 SCAR=37.4
52  
53 0 ▶ return unless (defined $_val);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_val 0 0 0
54 0 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 0 0
55  
56 0 ▶ if (length ${ $_[1] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (length ${$_[1];}) 0 0 0
57 0 my $_buf = $_[0]->{freeze}([ $_val, ${ $_[1] } ]);
58 0 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
59 0 print({$_DAT_W_SOCK} OUTPUT_F_SND.$LF . $_chn.$LF),
60 0 print({$_DAU_W_SOCK} length($_buf).$LF, $_buf);
61 0 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
62 }
63  
64 0 return;
65 94 };
66  
67 0 ▶ $_dest_function[SENDTO_FD] = sub { ## Content >> File descriptor
Subroutine __ANON__: not called CC=6 SCAR=37.4
68  
69 0 ▶ return unless (defined $_val);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_val 0 0 0
70 0 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 0 0
71  
72 0 ▶ if (length ${ $_[1] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (length ${$_[1];}) 0 0 0
73 0 my $_buf = $_[0]->{freeze}([ $_val, ${ $_[1] } ]);
74 0 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
75 0 print({$_DAT_W_SOCK} OUTPUT_D_SND.$LF . $_chn.$LF),
76 0 print({$_DAU_W_SOCK} length($_buf).$LF, $_buf);
77 0 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
78 }
79  
80 0 return;
81 94 };
82  
83 0 ▶ $_dest_function[SENDTO_STDOUT] = sub { ## Content >> STDOUT
Subroutine __ANON__: not called CC=5 SCAR=34.0
84  
85 0 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 0 0
86  
87 0 ▶ if (length ${ $_[1] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (length ${$_[1];}) 0 0 0
88 0 my $_buf = $_[0]->{freeze}($_[1]);
89 0 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
90 0 print({$_DAT_W_SOCK} OUTPUT_O_SND.$LF . $_chn.$LF),
91 0 print({$_DAU_W_SOCK} length($_buf).$LF, $_buf);
92 0 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
93 }
94  
95 0 return;
96 94 };
97  
98 0 ▶ $_dest_function[SENDTO_STDERR] = sub { ## Content >> STDERR
Subroutine __ANON__: not called CC=5 SCAR=34.0
99  
100 0 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 0 0
101  
102 0 ▶ if (length ${ $_[1] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (length ${$_[1];}) 0 0 0
103 0 my $_buf = $_[0]->{freeze}($_[1]);
104 0 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
105 0 print({$_DAT_W_SOCK} OUTPUT_E_SND.$LF . $_chn.$LF),
106 0 print({$_DAU_W_SOCK} length($_buf).$LF, $_buf);
107 0 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
108 }
109  
110 0 return;
111 94 };
112  
113 ## -------------------------------------------------------------------------
114  
115 133 ▶ sub _do_callback {
Subroutine _do_callback: called CC=12 SCAR=25.1
116  
117 133 my ($self, $_buf, $_aref);
118  
119 133 ($self, $_val, $_aref) = @_;
120  
121 133 ▶ unless (defined wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined wantarray) { } 7 126 133
if (do { wantarray }) { } 2 5 7
122 126 $_wa = WANTS_UNDEF;
123 } elsif (wantarray) {
124 2 $_wa = WANTS_ARRAY;
125 } else {
126 5 $_wa = WANTS_SCALAR;
127 }
128  
129 133 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 133 133
130  
131 ## Crossover: Send arguments
132  
133 133 ▶ if ( ! @{ $_aref } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$_aref;}) { } 2 131 133
134 2 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 2 2
135 2 print({$_DAT_W_SOCK} OUTPUT_N_CBK.$LF . $_chn.$LF),
136 2 print({$_DAU_W_SOCK} $_wa.$LF . $_val.$LF);
137 }
138 else {
139 131 $_buf = $self->{freeze}($_aref);
140 131 $_len = length $_buf;
141  
142 131 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 131 131
143 131 print({$_DAT_W_SOCK} OUTPUT_A_CBK.$LF . $_chn.$LF),
144 131 print({$_DAU_W_SOCK} $_wa.$LF . $_val.$LF . $_len.$LF, $_buf);
145 }
146  
147 ## Crossover: Receive value
148  
149 133 ▶ if ( $_wa ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_wa) 7 126 133
150 7 ▶ local $/ = $LF if ($/ ne $LF);
Branch: 1 branch
BranchTrueFalseTotal
if $/ ne $MCE::LF 0 7 7
151 7 chomp(my $_len = <$_DAU_W_SOCK>);
152  
153 7 read $_DAU_W_SOCK, my($_buf), $_len;
154 7 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 7 7
155  
156 return ( $_wa != WANTS_ARRAY )
157 ? ($self->{thaw}($_buf))->[0]
158 7 ▶ : @{ $self->{thaw}($_buf) };
Branch: 1 branch
BranchTrueFalseTotal
$_wa != 1 ? : 5 2 7
159 }
160  
161 126 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 126 126
162 }
163  
164 ## -------------------------------------------------------------------------
165  
166 365 ▶ sub _do_gather {
Subroutine _do_gather: called CC=5 SCAR=16.4
167  
168 365 my $_buf; my ($self, $_aref) = @_;
169  
170 365 ▶ return unless (scalar @{ $_aref });
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$_aref;} 0 365 365
171  
172 365 $_tag = OUTPUT_A_GTR;
173 365 $_buf = $self->{freeze}($_aref);
174 365 $_len = length $_buf;
175  
176 365 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 365 365
177  
178 365 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 365 365
179 365 print({$_DAT_W_SOCK} $_tag.$LF . $_chn.$LF),
180 365 print({$_DAU_W_SOCK} $_task_id.$LF . $_len.$LF, $_buf);
181 365 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 365 365
182  
183 365 return;
184 }
185  
186 ## -------------------------------------------------------------------------
187  
188 0 ▶ sub _do_send {
Subroutine _do_send: not called CC=6 SCAR=37.4
189  
190 0 my $_data_ref; my $self = shift;
191  
192 0 $_dest = shift; $_val = shift;
193  
194 0 ▶ if (scalar @_ > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ > 1) { } 0 0 0
elsif (my $_ref = ref $_[0]) { } 0 0 0
195 0 $_data_ref = \join('', @_);
196 }
197 elsif (my $_ref = ref $_[0]) {
198 0 ▶ if ($_ref eq 'SCALAR') {
Branch: 3 branches
BranchTrueFalseTotal
if ($_ref eq 'SCALAR') { } 0 0 0
elsif ($_ref eq 'ARRAY') { } 0 0 0
elsif ($_ref eq 'HASH') { } 0 0 0
199 0 $_data_ref = $_[0];
200 }
201 elsif ($_ref eq 'ARRAY') {
202 0 $_data_ref = \join('', @{ $_[0] });
203 }
204 elsif ($_ref eq 'HASH') {
205 0 $_data_ref = \join('', %{ $_[0] });
206 }
207 else {
208 0 $_data_ref = \join('', @_);
209 }
210 }
211 else {
212 0 $_data_ref = \(''.$_[0]);
213 }
214  
215 0 $_dest_function[$_dest]($self, $_data_ref);
216  
217 0 return 1;
218 }
219  
220 0 ▶ sub _do_send_glob {
Subroutine _do_send_glob: not called CC=5 SCAR=30.7
221  
222 0 my ($self, $_glob, $_fd, $_data_ref) = @_;
223  
224 0 ▶ if ($self->{_wid} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_wid'} > 0) { } 0 0 0
225 0 ▶ if ($_fd == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_fd == 1) { } 0 0 0
elsif ($_fd == 2) { } 0 0 0
226 0 _do_send($self, SENDTO_STDOUT, undef, $_data_ref);
227 }
228 elsif ($_fd == 2) {
229 0 _do_send($self, SENDTO_STDERR, undef, $_data_ref);
230 }
231 else {
232 0 _do_send($self, SENDTO_FD, $_fd, $_data_ref);
233 }
234 }
235 else {
236 94 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
237 0 my $_fh = _sendto_fhs_get($self, $_fd);
238 0 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 0 0
239  
240 0 print {$_fh} ${ $_data_ref };
241 }
242  
243 0 return 1;
244 }
245  
246 ## -------------------------------------------------------------------------
247  
248 73 ▶ sub _do_send_init {
Subroutine _do_send_init: called CC=4 SCAR=19.1
249  
250 73 my ($self) = @_;
251  
252 73 $_chn = $self->{_chn};
253 73 $_DAT_LOCK = $self->{_dat_lock};
254 73 $_DAT_W_SOCK = $self->{_dat_w_sock}->[0];
255 73 $_DAU_W_SOCK = $self->{_dat_w_sock}->[$_chn];
256 73 $_lock_chn = $self->{_lock_chn};
257 73 $_task_id = $self->{_task_id};
258  
259 73 ▶ if ($_lock_chn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_lock_chn) 0 73 73
260 # inlined for performance
261 0 ▶ $_dat_ex = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
262 0 ▶ my $_pid = $_tid ? $$ .'.'. $_tid : $$;
Branch: 1 branch
BranchTrueFalseTotal
$_tid ? : 0 0 0
263 CORE::lock($_DAT_LOCK->{_t_lock}), MCE::Util::_sock_ready($_DAT_LOCK->{_r_sock})
264 0 ▶ if $_is_MSWin32;
Branch: 1 branch
BranchTrueFalseTotal
if $_is_MSWin32 0 0 0
265 MCE::Util::_sysread($_DAT_LOCK->{_r_sock}, my($b), 1), $_DAT_LOCK->{ $_pid } = 1
266 0 ▶ unless $_DAT_LOCK->{ $_pid };
Branch: 1 branch
BranchTrueFalseTotal
unless $_DAT_LOCK->{$_pid} 0 0 0
267 0 };
268 0 ▶ $_dat_un = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
269 0 ▶ my $_pid = $_tid ? $$ .'.'. $_tid : $$;
Branch: 1 branch
BranchTrueFalseTotal
$_tid ? : 0 0 0
270 syswrite($_DAT_LOCK->{_w_sock}, '0'), $_DAT_LOCK->{ $_pid } = 0
271 0 ▶ if $_DAT_LOCK->{ $_pid };
Branch: 1 branch
BranchTrueFalseTotal
if $_DAT_LOCK->{$_pid} 0 0 0
272 0 };
273 }
274  
275 {
276 73 local $!;
277 73 ▶ (*STDERR)->autoflush(1) if defined( fileno *STDERR );
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDERR 73 0 73
278 73 ▶ (*STDOUT)->autoflush(1) if defined( fileno *STDOUT );
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno STDOUT 73 0 73
279 }
280  
281 73 return;
282 }
283  
284 73 ▶ sub _do_send_clear {
Subroutine _do_send_clear: called CC=1 SCAR=0.0
285  
286 73 my ($self) = @_;
287  
288 73 $_dest = $_len = $_task_id = $_user_func = $_val = $_wa = undef;
289 73 $_DAT_LOCK = $_DAT_W_SOCK = $_DAU_W_SOCK = $_chn = $_lock_chn = undef;
290 73 $_dat_ex = $_dat_un = $_tag = undef;
291  
292 73 return;
293 }
294  
295 ## -------------------------------------------------------------------------
296  
297 250 ▶ sub _do_user_func {
Subroutine _do_user_func: called CC=23 SCAR=55.6
298  
299 250 my ($self, $_chunk, $_chunk_id) = @_;
300 250 my $_size = 0;
301  
302 250 delete $self->{_relayed};
303 250 $self->{_chunk_id} = $_chunk_id;
304  
305 250 ▶ if ($self->{progress} && $self->{_task_id} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"progress"} and $self->{"_task_id"} == 0) 0 250 250
Condition33%1/3
$self->{"progress"} and $self->{"_task_id"} == 0
!ll&&!rl&&r
25000
MC/DC0%0/2
$self->{"progress"} and $self->{"_task_id"} == 0
$self->{"progress"} $self->{"_task_id"} == 0
Truth table33%1/3
A and B
A= $self->{"progress"}B= $self->{"_task_id"} == 0
ABresult
0X0
100
111
306 # use_slurpio
307 0 ▶ if (ref $_chunk eq 'SCALAR') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_chunk eq 'SCALAR') { } 0 0 0
elsif ($self->{'sequence'} and $self->{'bounds_only'}) { } 0 0 0
elsif ($self->{'input_data'}) { } 0 0 0
308 0 $_size += length ${ $_chunk };
309 }
310 # sequence and bounds_only
311 ▶ elsif ($self->{sequence} && $self->{bounds_only}) {
Condition0%0/3
$self->{"sequence"} and $self->{"bounds_only"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"sequence"} and $self->{"bounds_only"}
$self->{"sequence"} $self->{"bounds_only"}
Truth table0%0/3
A and B
A= $self->{"sequence"}B= $self->{"bounds_only"}
ABresult
0X0
100
111
312 0 my $_seq = $self->{sequence};
313 0 ▶ my $_step = (ref $_seq eq 'ARRAY') ? $_seq->[2] : $_seq->{step};
Branch: 1 branch
BranchTrueFalseTotal
ref $_seq eq 'ARRAY' ? : 0 0 0
314 0 $_size += int(abs($_chunk->[0] - $_chunk->[1]) / abs($_step)) + 1;
315 }
316 # workers clear {input_data} to conserve memory when array ref
317 # otherwise, /path/to/infile or scalar reference
318 elsif ($self->{input_data}) {
319 0 map { $_size += length } @{ $_chunk };
320 }
321 # array or sequence
322 else {
323 0 ▶ $_size += (ref $_chunk eq 'ARRAY') ? @{ $_chunk } : 1;
Branch: 1 branch
BranchTrueFalseTotal
ref $_chunk eq 'ARRAY' ? : 0 0 0
324 }
325 }
326  
327 250 ▶ if ($self->{max_retries}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max_retries"}) 0 250 250
328 0 $self->{_retry} = [ $_chunk, $_chunk_id, $self->{max_retries} ];
329 }
330  
331 250 ▶ if ($self->{loop_timeout} && $self->{_task_id} == 0 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"loop_timeout"} and $self->{"_task_id"} == 0 and defined $self->{"init_relay"} and not $self->{"_is_thread"} and not $_is_MSWin32) 0 250 250
Condition33%4/12
$self->{"loop_timeout"} and $self->{"_task_id"} == 0 and defined $self->{"init_relay"} and not $self->{"_is_thread"} and not $_is_MSWin32
!ll&&!rl&&r
25000
$self->{"loop_timeout"} and $self->{"_task_id"} == 0 and defined $self->{"init_relay"} and not $self->{"_is_thread"}
!ll&&!rl&&r
25000
$self->{"loop_timeout"} and $self->{"_task_id"} == 0 and defined $self->{"init_relay"}
!ll&&!rl&&r
25000
$self->{"loop_timeout"} and $self->{"_task_id"} == 0
!ll&&!rl&&r
25000
MC/DC0%0/5
$self->{"loop_timeout"} and $self->{"_task_id"} == 0 and defined $self->{"init_relay"} and not $self->{"_is_thread"} and not $_is_MSWin32
$self->{"loop_timeout"} $self->{"_task_id"} == 0 defined $self->{"init_relay"} not $self->{"_is_thread"} not $_is_MSWin32
Truth table16%1/6
A and B and C and not(D) and not(E)
A= $self->{"loop_timeout"}B= $self->{"_task_id"} == 0C= defined $self->{"init_relay"}D= not $self->{"_is_thread"}E= not $_is_MSWin32
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
332 defined $self->{init_relay} && !$self->{_is_thread} && !$_is_MSWin32) {
333  
334 0 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 0 0
335  
336 0 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
337 0 print({$_DAT_W_SOCK} OUTPUT_C_NFY.$LF . $_chn.$LF),
338 0 print({$_DAU_W_SOCK} "$$:$_chunk_id".$LF);
339 0 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
340 }
341  
342 250 $_user_func->($self, $_chunk, $_chunk_id);
343  
344 250 ▶ if ($self->{progress} && $self->{_task_id} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"progress"} and $self->{"_task_id"} == 0) 0 250 250
Condition33%1/3
$self->{"progress"} and $self->{"_task_id"} == 0
!ll&&!rl&&r
25000
MC/DC0%0/2
$self->{"progress"} and $self->{"_task_id"} == 0
$self->{"progress"} $self->{"_task_id"} == 0
Truth table33%1/3
A and B
A= $self->{"progress"}B= $self->{"_task_id"} == 0
ABresult
0X0
100
111
345 0 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 0 0
346  
347 0 ▶ $_dat_ex->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
348 0 print({$_DAT_W_SOCK} OUTPUT_P_NFY.$LF . $_chn.$LF),
349 0 print({$_DAU_W_SOCK} $_size.$LF);
350 0 ▶ $_dat_un->() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 0 0
351 }
352  
353 250 return;
354 }
355  
356 171 ▶ sub _do_user_func_init {
Subroutine _do_user_func_init: called CC=1 SCAR=0.0
357  
358 171 my ($self) = @_;
359  
360 171 $_user_func = $self->{user_func};
361  
362 171 return;
363 }
364 }
365  
366 ###############################################################################
367 ## ----------------------------------------------------------------------------
368 ## Worker process -- Do.
369 ##
370 ###############################################################################
371  
372 94 ▶sub MCE::Core::Worker::_guard::DESTROY {
Subroutine DESTROY: called CC=3 SCAR=14.2
373  
374 171 my ($mce, $id) = @{ $_[0] };
375  
376 171 ▶ if (defined $mce && $id eq "$$.$_tid") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mce and $id eq "${$}.$_tid") 0 171 171
Condition33%1/3
defined $mce and $id eq "${$}.$_tid"
!ll&&!rl&&r
17100
MC/DC0%0/2
defined $mce and $id eq "${$}.$_tid"
defined $mce $id eq "${$}.$_tid"
Truth table33%1/3
A and B
A= defined $mceB= $id eq "${$}.$_tid"
ABresult
0X0
100
111
377 0 @{ $_[0] } = ();
378 0 warn "MCE worker $id exited prematurely.\n";
379 0 $mce->exit(2);
380 }
381  
382 171 return;
383 };
384  
385 171 ▶sub _worker_do {
Subroutine _worker_do: called CC=39 SCAR=47.2
386  
387 171 my ($self, $_params_ref) = @_;
388  
389 171 @_ = ();
390  
391 ## Set options.
392 171 $self->{_abort_msg} = $_params_ref->{_abort_msg};
393 171 $self->{_run_mode} = $_params_ref->{_run_mode};
394 171 $self->{use_slurpio} = $_params_ref->{_use_slurpio};
395 171 $self->{parallel_io} = $_params_ref->{_parallel_io};
396 171 $self->{progress} = $_params_ref->{_progress};
397 171 $self->{max_retries} = $_params_ref->{_max_retries};
398 171 $self->{RS} = $_params_ref->{_RS};
399  
400 171 _do_user_func_init($self);
401  
402 ## Init local vars.
403 171 my $_chn = $self->{_chn};
404 171 my $_DAT_LOCK = $self->{_dat_lock};
405 171 my $_DAT_W_SOCK = $self->{_dat_w_sock}->[0];
406 171 my $_DAU_W_SOCK = $self->{_dat_w_sock}->[$_chn];
407 171 my $_lock_chn = $self->{_lock_chn};
408 171 my $_run_mode = $self->{_run_mode};
409 171 my $_task_id = $self->{_task_id};
410 171 my $_task_name = $self->{task_name};
411  
412 ## Do not override params if defined in user_tasks during instantiation.
413 171 for my $_p (qw(bounds_only chunk_size sequence user_args)) {
414 684 ▶ if (defined $_params_ref->{"_${_p}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$_params_ref{"_$_p"}) 216 468 684
415 $self->{$_p} = $_params_ref->{"_${_p}"}
416 216 ▶ unless (defined $self->{_task}->{$_p});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_task"}{$_p} 216 0 216
417 }
418 }
419  
420 {
421 171 my $_guard = bless([ $self, "$$.$_tid" ], MCE::Core::Worker::_guard::);
422 171 weaken( $self->{_guard} = $_guard );
423  
424 ## Assign user function.
425 171 $self->{_wuf} = \&_do_user_func;
426  
427 ## Call user_begin if defined.
428 171 ▶ if (defined $self->{user_begin}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"user_begin"}) 0 171 171
429 0 $self->{_chunk_id} = 0;
430 0 $self->{user_begin}($self, $_task_id, $_task_name);
431 0 ▶ if ($_task_id == 0 && defined $self->{init_relay} && !$self->{_retry}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_task_id == 0 and defined $self->{"init_relay"} and not $self->{"_retry"}) 0 0 0
Condition0%0/6
$_task_id == 0 and defined $self->{"init_relay"} and not $self->{"_retry"}
!ll&&!rl&&r
000
$_task_id == 0 and defined $self->{"init_relay"}
!ll&&!rl&&r
000
MC/DC0%0/3
$_task_id == 0 and defined $self->{"init_relay"} and not $self->{"_retry"}
$_task_id == 0 defined $self->{"init_relay"} not $self->{"_retry"}
Truth table0%0/4
A and B and not(C)
A= $_task_id == 0B= defined $self->{"init_relay"}C= not $self->{"_retry"}
ABCresult
0XX0
10X0
1100
1111
432 0 $self->sync();
433 }
434 }
435  
436 ## Retry chunk if previous attempt died.
437 171 ▶ if ($self->{_retry}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_retry"}) 0 171 171
438 0 $self->{_chunk_id} = $self->{_retry}->[1];
439 0 $self->{user_func}->($self, $self->{_retry}->[0], $self->{_retry}->[1]);
440 0 delete $self->{_retry};
441 }
442  
443 ## Call worker function.
444 171 ▶ if ($_run_mode eq 'sequence') {
Branch: 9 branches
BranchTrueFalseTotal
if ($_run_mode eq 'sequence') { } 14 157 171
elsif (defined $self->{'_task'}{'sequence'}) { } 0 157 157
elsif ($_run_mode eq 'array') { } 40 117 157
elsif ($_run_mode eq 'glob') { } 14 103 117
elsif ($_run_mode eq 'hash') { } 3 100 103
elsif ($_run_mode eq 'iterator') { } 0 100 100
elsif ($_run_mode eq 'file') { } 14 86 100
elsif ($_run_mode eq 'memory') { } 0 86 86
elsif (defined $self->{'user_func'}) { } 86 0 86
445 require MCE::Core::Input::Sequence
446 14 ▶ unless $INC{'MCE/Core/Input/Sequence.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"MCE/Core/Input/Sequence.pm"} 12 2 14
447 14 _worker_sequence_queue($self);
448 }
449 elsif (defined $self->{_task}->{sequence}) {
450 require MCE::Core::Input::Generator
451 0 ▶ unless $INC{'MCE/Core/Input/Generator.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"MCE/Core/Input/Generator.pm"} 0 0 0
452 0 _worker_sequence_generator($self);
453 }
454 elsif ($_run_mode eq 'array') {
455 require MCE::Core::Input::Request
456 40 ▶ unless $INC{'MCE/Core/Input/Request.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"MCE/Core/Input/Request.pm"} 0 40 40
457 40 _worker_request_chunk($self, REQUEST_ARRAY);
458 }
459 elsif ($_run_mode eq 'glob') {
460 require MCE::Core::Input::Request
461 14 ▶ unless $INC{'MCE/Core/Input/Request.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"MCE/Core/Input/Request.pm"} 0 14 14
462 14 _worker_request_chunk($self, REQUEST_GLOB);
463 }
464 elsif ($_run_mode eq 'hash') {
465 require MCE::Core::Input::Request
466 3 ▶ unless $INC{'MCE/Core/Input/Request.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"MCE/Core/Input/Request.pm"} 0 3 3
467 3 _worker_request_chunk($self, REQUEST_HASH);
468 }
469 elsif ($_run_mode eq 'iterator') {
470 require MCE::Core::Input::Iterator
471 0 ▶ unless $INC{'MCE/Core/Input/Iterator.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"MCE/Core/Input/Iterator.pm"} 0 0 0
472 0 _worker_user_iterator($self);
473 }
474 elsif ($_run_mode eq 'file') {
475 require MCE::Core::Input::Handle
476 14 ▶ unless $INC{'MCE/Core/Input/Handle.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"MCE/Core/Input/Handle.pm"} 12 2 14
477 14 _worker_read_handle($self, READ_FILE, $_params_ref->{_input_file});
478 }
479 elsif ($_run_mode eq 'memory') {
480 require MCE::Core::Input::Handle
481 0 ▶ unless $INC{'MCE/Core/Input/Handle.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"MCE/Core/Input/Handle.pm"} 0 0 0
482 0 _worker_read_handle($self, READ_MEMORY, $self->{input_data});
483 }
484 elsif (defined $self->{user_func}) {
485 86 ▶ if ($self->{max_retries}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max_retries"}) 0 86 86
486 0 $self->{_retry} = [ undef, 0, $self->{max_retries} ];
487 }
488 86 $self->{_chunk_id} = 0;
489 86 $self->{user_func}->($self);
490 }
491  
492 171 ▶ undef $self->{_next_jmp} if (defined $self->{_next_jmp});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_next_jmp"} 95 76 171
493 171 ▶ undef $self->{_last_jmp} if (defined $self->{_last_jmp});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_last_jmp"} 95 76 171
494 171 ▶ undef $self->{user_data} if (defined $self->{user_data});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"user_data"} 0 171 171
495  
496 ## Call user_end if defined.
497 171 ▶ if (defined $self->{user_end}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"user_end"}) 0 171 171
498 0 $self->{_chunk_id} = 0;
499 0 ▶ $self->sync() if ($_task_id == 0 && defined $self->{init_relay});
Branch: 1 branch
BranchTrueFalseTotal
if $_task_id == 0 and defined $self->{"init_relay"} 0 0 0
Condition0%0/3
$_task_id == 0 and defined $self->{"init_relay"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_task_id == 0 and defined $self->{"init_relay"}
$_task_id == 0 defined $self->{"init_relay"}
Truth table0%0/3
A and B
A= $_task_id == 0B= defined $self->{"init_relay"}
ABresult
0X0
100
111
500 0 $self->{user_end}($self, $_task_id, $_task_name);
501 }
502  
503 171 @{ $_guard } = ();
504 171 delete $self->{_guard};
505 171 delete $self->{_wuf};
506 }
507  
508 ## Check for nested workers not yet joined.
509 171 ▶ MCE::Child->finish('MCE') if $INC{'MCE/Child.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"MCE/Child.pm"} 0 171 171
510 171 ▶ MCE::Hobo->finish('MCE') if $INC{'MCE/Hobo.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"MCE/Hobo.pm"} 0 171 171
511  
512 ## Notify the main process a worker has completed.
513 171 ▶ local $\ = undef if (defined $\);
Branch: 1 branch
BranchTrueFalseTotal
if defined $\ 0 171 171
514  
515 171 ▶ $_DAT_LOCK->lock() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 171 171
516  
517 171 print({$_DAT_W_SOCK} OUTPUT_W_DNE.$LF . $_chn.$LF),
518 171 print({$_DAU_W_SOCK} $_task_id.$LF);
519  
520 171 ▶ $_DAT_LOCK->unlock() if $_lock_chn;
Branch: 1 branch
BranchTrueFalseTotal
if $_lock_chn 0 171 171
521  
522 171 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 171 171
523 0 lock $self->{_run_lock};
524 }
525  
526 171 return;
527 }
528  
529 ###############################################################################
530 ## ----------------------------------------------------------------------------
531 ## Worker process -- Loop.
532 ##
533 ###############################################################################
534  
535 73 ▶sub _worker_loop {
Subroutine _worker_loop: called CC=10 SCAR=27.7
536  
537 73 my ($self) = @_;
538  
539 73 @_ = ();
540  
541 73 my ($_response, $_len, $_buf, $_params_ref);
542  
543 73 my $_COM_LOCK = $self->{_com_lock};
544 73 my $_COM_W_SOCK = $self->{_com_w_sock};
545 73 my $_job_delay = $self->{job_delay};
546  
547 0 ▶ if ($^O eq 'MSWin32') { lock $MCE::_WIN_LOCK; }
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 73 73
548  
549 73 while (1) {
550 {
551 244 local $\ = undef; local $/ = $LF;
552 244 $_COM_LOCK->lock();
553  
554 ## Wait for the next job request.
555 244 $_response = <$_COM_W_SOCK>, print {$_COM_W_SOCK} $self->{_wid}.$LF;
556  
557 ## Return if instructed to exit.
558 244 ▶ $_COM_LOCK->unlock(), return if ($_response eq "_exit\n");
Branch: 1 branch
BranchTrueFalseTotal
if $_response eq "_exit\n" 73 171 244
559  
560 ## Process send request.
561 171 ▶ if ($_response eq "_data\n") {
Branch: 2 branches
BranchTrueFalseTotal
if ($_response eq "_data\n") { } 0 171 171
elsif ($_response =~ /\d+/) { } 171 0 171
562 0 chomp($_len = <$_COM_W_SOCK>), read($_COM_W_SOCK, $_buf, $_len);
563 0 print({$_COM_W_SOCK} $LF), $_COM_LOCK->unlock();
564 0 $self->{user_data} = $self->{thaw}($_buf), undef $_buf;
565  
566 sleep $_job_delay * $self->{_wid}
567 0 ▶ if defined($_job_delay) && $_job_delay > 0.0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_job_delay and $_job_delay > 0 0 0 0
Condition0%0/3
defined $_job_delay and $_job_delay > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_job_delay and $_job_delay > 0
defined $_job_delay $_job_delay > 0
Truth table0%0/3
A and B
A= defined $_job_delayB= $_job_delay > 0
ABresult
0X0
100
111
568 }
569  
570 ## Process normal request.
571 elsif ($_response =~ /\d+/) {
572 171 chomp($_len = <$_COM_W_SOCK>), read($_COM_W_SOCK, $_buf, $_len);
573 171 print({$_COM_W_SOCK} $LF), $_COM_LOCK->unlock();
574 171 $_params_ref = $self->{thaw}($_buf), undef $_buf;
575 }
576  
577 ## Leave loop if invalid response.
578 else {
579 0 last;
580 }
581 }
582  
583 ## Send request.
584 171 ▶ _worker_do($self, {}), next if ($_response eq "_data\n");
Branch: 1 branch
BranchTrueFalseTotal
if $_response eq "_data\n" 0 171 171
585  
586 ## Wait here until MCE completes job submission to all workers.
587 171 MCE::Util::_sysread($self->{_bsb_w_sock}, my($_b), 1);
588  
589 ## Normal request.
590 sleep $_job_delay * $self->{_wid}
591 171 ▶ if defined($_job_delay) && $_job_delay > 0.0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_job_delay and $_job_delay > 0 0 171 171
Condition33%1/3
defined $_job_delay and $_job_delay > 0
!ll&&!rl&&r
17100
MC/DC0%0/2
defined $_job_delay and $_job_delay > 0
defined $_job_delay $_job_delay > 0
Truth table33%1/3
A and B
A= defined $_job_delayB= $_job_delay > 0
ABresult
0X0
100
111
592  
593 171 _worker_do($self, $_params_ref); undef $_params_ref;
594 }
595  
596 ## Notify the main process a worker has ended. The following is executed
597 ## when an invalid reply was received above (not likely to occur).
598  
599 0 $_COM_LOCK->unlock();
600  
601 0 die "Error: worker $self->{_wid} has ended prematurely";
602 }
603  
604 ###############################################################################
605 ## ----------------------------------------------------------------------------
606 ## Worker process -- Main.
607 ##
608 ###############################################################################
609  
610 73 ▶sub _worker_main {
Subroutine _worker_main: called CC=26 SCAR=44.5
611  
612 73 my ( $self, $_wid, $_task, $_task_id, $_task_wid, $_params,
613 $_plugin_worker_init ) = @_;
614  
615 73 @_ = ();
616  
617 73 ▶ if (exists $self->{input_data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"input_data"}) 31 42 73
618 31 my $_ref = ref $self->{input_data};
619 31 ▶ delete $self->{input_data} if ($_ref && $_ref ne 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if $_ref and $_ref ne "SCALAR" 31 0 31
Condition33%1/3
$_ref and $_ref ne "SCALAR"
!ll&&!rl&&r
0031
MC/DC0%0/2
$_ref and $_ref ne "SCALAR"
$_ref $_ref ne "SCALAR"
Truth table33%1/3
A and B
A= $_refB= $_ref ne "SCALAR"
ABresult
0X0
100
111
620 }
621  
622 73 ▶ $self->{_task_id} = (defined $_task_id ) ? $_task_id : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_task_id ? : 50 23 73
623 73 ▶ $self->{_task_wid} = (defined $_task_wid) ? $_task_wid : $_wid;
Branch: 1 branch
BranchTrueFalseTotal
defined $_task_wid ? : 50 23 73
624 73 $self->{_task} = $_task;
625 73 $self->{_wid} = $_wid;
626  
627 ## Define exit pid and DIE handler.
628 my $_use_threads = (defined $_task->{use_threads})
629 73 ▶ ? $_task->{use_threads} : $self->{use_threads};
Branch: 1 branch
BranchTrueFalseTotal
defined $_task->{'use_threads'} ? : 50 23 73
630  
631 73 ▶ if ($INC{'threads.pm'} && $_use_threads) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{'threads.pm'} and $_use_threads) { } 0 73 73
Condition33%1/3
$INC{"threads.pm"} and $_use_threads
!ll&&!rl&&r
7300
MC/DC0%0/2
$INC{"threads.pm"} and $_use_threads
$INC{"threads.pm"} $_use_threads
Truth table33%1/3
A and B
A= $INC{"threads.pm"}B= $_use_threads
ABresult
0X0
100
111
632 0 $self->{_exit_pid} = 'TID_' . $_tid;
633 } else {
634 73 $self->{_exit_pid} = 'PID_' . $$;
635 }
636  
637 73 my $_running_inside_eval = $^S;
638  
639 0 ▶ local $SIG{SEGV} = sub { $self->exit(11) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
640  
641 0 ▶ local $SIG{__DIE__} = sub {
Subroutine __ANON__: not called CC=10 SCAR=47.0
642 0 ▶ if (!defined $^S || $^S) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $^S or $^S) 0 0 0
Condition0%0/3
not defined $^S or $^S
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $^S or $^S
not defined $^S $^S
Truth table0%0/3
not(A) or B
A= not defined $^SB= $^S
ABresult
1X1
011
000
643 0 ▶ if ( ($INC{'threads.pm'} && $_tid != 0) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{'threads.pm'} and $_tid != 0 or $ENV{'PERL_IPERL_RUNNING'} or $_running_inside_eval) { } 0 0 0
Condition0%0/9
$INC{"threads.pm"} and $_tid != 0 or $ENV{"PERL_IPERL_RUNNING"} or $_running_inside_eval
l!l&&r!l&&!r
000
$INC{"threads.pm"} and $_tid != 0 or $ENV{"PERL_IPERL_RUNNING"}
l!l&&r!l&&!r
000
$INC{"threads.pm"} and $_tid != 0
!ll&&!rl&&r
000
MC/DC0%0/4
$INC{"threads.pm"} and $_tid != 0 or $ENV{"PERL_IPERL_RUNNING"} or $_running_inside_eval
$INC{"threads.pm"} $_tid != 0 $ENV{"PERL_IPERL_RUNNING"} $_running_inside_eval
Truth table0%0/7
A and B or C or D
A= $INC{"threads.pm"}B= $_tid != 0C= $ENV{"PERL_IPERL_RUNNING"}D= $_running_inside_eval
ABCDresult
11XX1
0X1X1
101X1
0X011
10011
0X000
10000
644 $ENV{'PERL_IPERL_RUNNING'} ||
645 $_running_inside_eval
646 ) {
647 # thread env or running inside IPerl, check stack trace
648 0 my $_t = Carp::longmess(); $_t =~ s/\teval [^\n]+\n$//;
649 0 ▶ if ( $_t =~ /^(?:[^\n]+\n){1,7}\teval / ||
Branch: 1 branch
BranchTrueFalseTotal
if ($_t =~ /^(?:[^\n]+\n){1,7}\teval / or $_t =~ /\n\teval [^\n]+\n\t(?:eval|Try)/) 0 0 0
Condition0%0/3
$_t =~ /^(?:[^\n]+\n){1,7}\teval / or $_t =~ /\n\teval [^\n]+\n\t(?:eval|Try)/
l!l&&r!l&&!r
000
MC/DC0%0/2
$_t =~ /^(?:[^\n]+\n){1,7}\teval / or $_t =~ /\n\teval [^\n]+\n\t(?:eval|Try)/
$_t =~ /^(?:[^\n]+\n){1,7}\teval / $_t =~ /\n\teval [^\n]+\n\t(?:eval|Try)/
Truth table0%0/3
A or B
A= $_t =~ /^(?:[^\n]+\n){1,7}\teval /B= $_t =~ /\n\teval [^\n]+\n\t(?:eval|Try)/
ABresult
1X1
011
000
650 $_t =~ /\n\teval [^\n]+\n\t(?:eval|Try)/ )
651 {
652 0 CORE::die(@_);
653 }
654 }
655 else {
656 # normal env, trust $^S
657 0 CORE::die(@_);
658 }
659 }
660  
661 0 ▶ $SIG{__DIE__} = $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
662 0 ▶ my $_die_msg = (defined $_[0]) ? $_[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
663 0 $_die_msg =~ s/, <__ANONIO__> line \d+//;
664 0 local $\ = undef; print {*STDERR} $_die_msg;
665  
666 0 $self->exit(255, $_die_msg, $self->{_chunk_id});
667 73 };
668  
669 ## Use options from user_tasks if defined.
670 73 ▶ $self->{max_workers} = $_task->{max_workers} if ($_task->{max_workers});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"max_workers"} 50 23 73
671 73 ▶ $self->{chunk_size} = $_task->{chunk_size} if ($_task->{chunk_size});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"chunk_size"} 0 73 73
672 73 ▶ $self->{gather} = $_task->{gather} if ($_task->{gather});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"gather"} 8 65 73
673 73 ▶ $self->{sequence} = $_task->{sequence} if ($_task->{sequence});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"sequence"} 0 73 73
674 73 ▶ $self->{bounds_only} = $_task->{bounds_only} if ($_task->{bounds_only});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"bounds_only"} 0 73 73
675 73 ▶ $self->{task_name} = $_task->{task_name} if ($_task->{task_name});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"task_name"} 16 57 73
676 73 ▶ $self->{user_args} = $_task->{user_args} if ($_task->{user_args});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"user_args"} 0 73 73
677 73 ▶ $self->{user_begin} = $_task->{user_begin} if ($_task->{user_begin});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"user_begin"} 0 73 73
678 73 ▶ $self->{user_func} = $_task->{user_func} if ($_task->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"user_func"} 50 23 73
679 73 ▶ $self->{user_end} = $_task->{user_end} if ($_task->{user_end});
Branch: 1 branch
BranchTrueFalseTotal
if $_task->{"user_end"} 0 73 73
680  
681 ## Init runtime vars. Obtain handle to lock files.
682 73 my $_chn;
683  
684 73 ▶ if (defined $_params && exists $_params->{_chn}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_params and exists $_params->{'_chn'}) { } 0 73 73
Condition33%1/3
defined $_params and exists $_params->{"_chn"}
!ll&&!rl&&r
7300
MC/DC0%0/2
defined $_params and exists $_params->{"_chn"}
defined $_params exists $_params->{"_chn"}
Truth table33%1/3
A and B
A= defined $_paramsB= exists $_params->{"_chn"}
ABresult
0X0
100
111
685 0 $_chn = $self->{_chn} = delete $_params->{_chn}; # worker restarted
686 } else {
687 73 $_chn = $self->{_chn} = $_wid % $self->{_data_channels} + 1; # default
688 }
689  
690 ## Choose locks for DATA channels.
691 73 $self->{_com_lock} = $self->{'_mutex_0'};
692 73 ▶ $self->{_dat_lock} = $self->{'_mutex_'.$_chn} if ($self->{_lock_chn});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_lock_chn"} 0 73 73
693  
694 ## Delete attributes no longer required after being spawned.
695 73 delete @{ $self }{ qw(
696 flush_file flush_stderr flush_stdout stderr_file stdout_file
697 on_post_exit on_post_run user_data user_error user_output
698 _pids _state _status _thrs _tids
699 ) };
700  
701 ## Call MCE::Shared's init routine if present; enables parallel IPC.
702 ## For threads, init is called automatically via the CLONE feature.
703 73 ▶ MCE::Shared::init() if (!$_use_threads && $INC{'MCE/Shared.pm'});
Branch: 1 branch
BranchTrueFalseTotal
if not $_use_threads and $INC{"MCE/Shared.pm"} 0 73 73
Condition33%1/3
not $_use_threads and $INC{"MCE/Shared.pm"}
!ll&&!rl&&r
0730
MC/DC0%0/2
not $_use_threads and $INC{"MCE/Shared.pm"}
not $_use_threads $INC{"MCE/Shared.pm"}
Truth table33%1/3
not(A) and B
A= not $_use_threadsB= $INC{"MCE/Shared.pm"}
ABresult
0X0
100
111
704  
705 73 _do_send_init($self);
706  
707 ## Call module's worker_init routine for modules plugged into MCE.
708 73 for my $_p (@{ $_plugin_worker_init }) { $_p->($self); }
709  
710 ## Begin processing if worker was added during processing.
711 73 ▶ _worker_do($self, $_params), undef $_params if defined($_params);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_params 0 73 73
712  
713 ## Enter worker loop.
714 73 _worker_loop($self);
715  
716 ## Clear worker session.
717 73 _do_send_clear($self);
718  
719 73 $self->{_com_lock} = undef;
720 73 $self->{_dat_lock} = undef;
721  
722 73 return;
723 }
724  
725 94 1;
726  
727 __END__
« MCE/Core/Input/Iterator.pm ↑ Summary MCE/Step.pm »