| 1 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Extends Many-Core Engine with relay capabilities. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 5 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | package MCE::Relay; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | no warnings qw( threads recursion uninitialized numeric ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | our $VERSION = '1.904'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | ## no critic (Subroutines::ProhibitSubroutinePrototypes) | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | OUTPUT_W_RLA => 'W~RLA', # Worker has relayed | |||||||||||||||||||||||||||||||||||||||||
| 20 | OUTPUT_R_NFY => 'R~NFY', # Relay notification | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ## Import routine. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 10 | my $LF = "\012"; Internals::SvREADONLY($LF, 1); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 10 | my $_imported; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | ▶ | return if ($_imported++); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 10 | ▶ | if ($INC{'MCE.pm'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | _mce_m_init(); | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $\ = undef; require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | Carp::croak( | |||||||||||||||||||||||||||||||||||||||||
| 42 | "MCE::Relay cannot be used directly. Please consult the MCE::Relay\n". | ||||||||||||||||||||||||||||||||||||||||||
| 43 | "documentation for more information.\n\n" | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | return; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ## Output routines for the manager process. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | my ($_MCE, $_DAU_R_SOCK_REF, $_DAU_R_SOCK, $_rla_nextid, $_max_workers); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | my %_output_function = ( | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 122 | ▶ | OUTPUT_W_RLA.$LF => sub { # Worker has relayed | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 122 | ▶ | $_rla_nextid = 0 if ( ++$_rla_nextid == $_max_workers ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 122 | return; | |||||||||||||||||||||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 122 | ▶ | OUTPUT_R_NFY.$LF => sub { # Relay notification | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 122 | $_MCE->{_relayed}++; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 122 | return; | |||||||||||||||||||||||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 16 | ▶ | sub _mce_m_loop_begin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mce_m_loop_begin: called CC=9 SCAR=22.2
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 16 | ($_MCE, $_DAU_R_SOCK_REF) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 16 | my $_caller = $_MCE->{_caller}; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | $_max_workers = (exists $_MCE->{user_tasks}) | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ? $_MCE->{user_tasks}[0]{max_workers} | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | ▶ | : $_MCE->{max_workers}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | ## Write initial relay data. | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 16 | ▶ | if (defined $_MCE->{init_relay}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 16 | my $_ref = ref $_MCE->{init_relay}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 16 | ▶ | MCE::_croak("MCE::Relay: (init_relay) is not valid") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$_ref ne "" and $_ref ne "HASH" and $_ref ne "ARRAY"
$_ref ne "" and $_ref ne "HASH"
MC/DC0%0/3
$_ref ne "" and $_ref ne "HASH" and $_ref ne "ARRAY"
$_ref ne ""
$_ref ne "HASH"
$_ref ne "ARRAY"
Truth table75%3/4
A and B and C
A= $_ref ne ""B= $_ref ne "HASH"C= $_ref ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | if ($_ref ne '' && $_ref ne 'HASH' && $_ref ne 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 16 | my $_RLA_W_SOCK = $_MCE->{_rla_w_sock}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 16 | my $_init_relay; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 16 | $_MCE->{_relayed} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 16 | ▶ | if (ref $_MCE->{init_relay} eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | $_init_relay = $_MCE->{freeze}(\$_MCE->{init_relay}) . '0'; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | elsif (ref $_MCE->{init_relay} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 5 | $_init_relay = $_MCE->{freeze}($_MCE->{init_relay}) . '1'; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | elsif (ref $_MCE->{init_relay} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 7 | $_init_relay = $_MCE->{freeze}($_MCE->{init_relay}) . '2'; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 16 | print {$_RLA_W_SOCK} length($_init_relay) . $LF . $_init_relay; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 16 | $_rla_nextid = 0; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | delete $MCE::RLA->{$_caller}; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 16 | ▶ | sub _mce_m_loop_end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mce_m_loop_end: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | ## Obtain final relay data. | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 16 | ▶ | if (defined $_MCE->{init_relay}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 16 | my $_RLA_R_SOCK = $_MCE->{_rla_r_sock}->[$_rla_nextid]; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 16 | my ($_caller, $_len, $_ret) = ($_MCE->{_caller}); | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 16 | delete $_MCE->{_relayed}; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 16 | ▶ | MCE::Util::_sock_ready($_RLA_R_SOCK, -1) if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 16 | chomp($_len = <$_RLA_R_SOCK>); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 16 | read $_RLA_R_SOCK, $_ret, $_len; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 16 | ▶ | if (chop $_ret) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 12 | $MCE::RLA->{$_caller} = $_MCE->{thaw}($_ret); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | $MCE::RLA->{$_caller} = ${ $_MCE->{thaw}($_ret) }; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | ## Clear variables. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 16 | $_MCE = $_DAU_R_SOCK_REF = $_DAU_R_SOCK = undef; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 16 | $_rla_nextid = $_max_workers = undef; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 10 | ▶ | sub _mce_m_init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mce_m_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 10 | MCE::_attach_plugin( | |||||||||||||||||||||||||||||||||||||||||
| 149 | \%_output_function, \&_mce_m_loop_begin, \&_mce_m_loop_end | ||||||||||||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 10 | return; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 158 | ## Relay methods. | ||||||||||||||||||||||||||||||||||||||||||
| 159 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 160 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | ## Items below are folded into MCE. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | package # hide from rpm | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | MCE; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 10 | ▶ | no warnings qw( threads recursion uninitialized redefine ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 10 | ▶ | use Scalar::Util qw( weaken ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 16 | ▶ | sub relay_final { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
relay_final: called CC=7 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 16 | ▶ | my $x = shift; my $self = ref($x) ? $x : $MCE::MCE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | _croak('MCE::relay_final: method is not allowed by the worker process') | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 16 | ▶ | if ($self->{_wid}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 16 | my $_caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 16 | ▶ | if (exists $MCE::RLA->{$_caller}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 16 | ▶ | if (ref $MCE::RLA->{$_caller} eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | return delete $MCE::RLA->{$_caller}; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | elsif (ref $MCE::RLA->{$_caller} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 5 | return %{ delete $MCE::RLA->{$_caller} }; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | elsif (ref $MCE::RLA->{$_caller} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 7 | return @{ delete $MCE::RLA->{$_caller} }; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | # should not reach the following line | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | delete $MCE::RLA->{$_caller}; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 24 | ▶ | sub relay_recv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
relay_recv: called CC=16 SCAR=29.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 24 | ▶ | my $x = shift; my $self = ref($x) ? $x : $MCE::MCE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | _croak('MCE::relay_recv: (init_relay) is not defined') | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 24 | ▶ | unless (defined $self->{init_relay}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | _croak('MCE::relay_recv: method is not allowed by the manager process') | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 24 | ▶ | unless ($self->{_wid}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | _croak('MCE::relay_recv: method is not allowed by task_id > 0') | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 24 | ▶ | if ($self->{_task_id} > 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 24 | my ($_chn, $_nxt, $_rdr, $_len, $_ref); local $_; | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 24 | ▶ | local $\ = undef if (defined $\); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 24 | ▶ | local $/ = $LF if ($/ ne $LF ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 24 | ▶ | $_chn = $self->{_chunk_id} || $self->{_wid}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'_chunk_id'} || $self->{'_wid'}
MC/DC0%0/2
$self->{'_chunk_id'} || $self->{'_wid'}
$self->{'_chunk_id'}
$self->{'_wid'}
Truth table33%1/3
A || B
A= $self->{'_chunk_id'}B= $self->{'_wid'}
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 24 | $_chn = ($_chn - 1) % $self->{max_workers}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 24 | $_nxt = $_chn + 1; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 24 | ▶ | $_nxt = 0 if ($_nxt == $self->{max_workers}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 24 | $_rdr = $self->{_rla_r_sock}->[$_chn]; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 24 | print {$self->{_dat_w_sock}->[0]} OUTPUT_W_RLA.$LF . '0'.$LF; | |||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 24 | ▶ | MCE::Util::_sock_ready($_rdr, -1) if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 24 | chomp($_len = <$_rdr>); | |||||||||||||||||||||||||||||||||||||||||
| 224 | 24 | read $_rdr, $_, $_len; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 24 | $_ref = chop $_; | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 24 | ▶ | if ($_ref == 0) { ## scalar value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 8 | $self->{_rla_data} = ${ $self->{thaw}($_) }; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 8 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | return $self->{_rla_data}; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | elsif ($_ref == 1) { ## hash reference | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 8 | $self->{_rla_data} = $self->{thaw}($_); | |||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | return %{ $self->{_rla_data} }; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | elsif ($_ref == 2) { ## array reference | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | $self->{_rla_data} = $self->{thaw}($_); | |||||||||||||||||||||||||||||||||||||||||
| 239 | 8 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | return @{ $self->{_rla_data} }; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 26 | ▶ | sub relay (;&) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
relay: called CC=27 SCAR=44.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 26 | my ($self, $_code); | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 26 | ▶ | if (ref $_[0] eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ($self, $_code) = ($MCE::MCE, shift); | |||||||||||||||||||||||||||||||||||||||||
| 252 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 26 | ▶ | my $x = shift; $self = ref($x) ? $x : $MCE::MCE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 26 | $_code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | _croak('MCE::relay: (init_relay) is not defined') | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 26 | ▶ | unless (defined $self->{init_relay}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | _croak('MCE::relay: method is not allowed by the manager process') | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 26 | ▶ | unless ($self->{_wid}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | _croak('MCE::relay: method is not allowed by task_id > 0') | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 26 | ▶ | if ($self->{_task_id} > 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 26 | ▶ | if (ref $_code ne 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | _croak('MCE::relay: argument is not a code block') if (defined $_code); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 26 | weaken $_code; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 26 | my ($_chn, $_cid, $_nxt, $_rdr, $_wtr); | |||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 26 | ▶ | local $\ = undef if (defined $\); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 26 | ▶ | local $/ = $LF if ($/ ne $LF ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 26 | ▶ | $_chn = $_cid = $self->{_chunk_id} || $self->{_wid}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'_chunk_id'} || $self->{'_wid'}
MC/DC0%0/2
$self->{'_chunk_id'} || $self->{'_wid'}
$self->{'_chunk_id'}
$self->{'_wid'}
Truth table33%1/3
A || B
A= $self->{'_chunk_id'}B= $self->{'_wid'}
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 26 | $_chn = ($_chn - 1) % $self->{max_workers}; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 26 | $_nxt = $_chn + 1; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 26 | ▶ | $_nxt = 0 if ($_nxt == $self->{max_workers}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 26 | $_rdr = $self->{_rla_r_sock}->[$_chn]; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 26 | $_wtr = $self->{_rla_w_sock}->[$_nxt]; | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 26 | ▶ | if (exists $self->{_rla_data}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 24 | my $_tmp; local $_ = delete $self->{_rla_data}; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 24 | ▶ | $_code->() if (ref $_code eq 'CODE'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 24 | ▶ | if (ref $_ eq '') { ## scalar value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 8 | $_tmp = $self->{freeze}(\$_) . '0'; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | elsif (ref $_ eq 'HASH') { ## hash reference | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 8 | $_tmp = $self->{freeze}($_) . '1'; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | elsif (ref $_ eq 'ARRAY') { ## array reference | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 8 | $_tmp = $self->{freeze}($_) . '2'; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 24 | print {$_wtr} length($_tmp) . $LF . $_tmp; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 24 | print {$self->{_dat_w_sock}->[0]} OUTPUT_R_NFY.$LF . '0'.$LF; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 24 | $self->{_relayed} = $_cid; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | my ($_len, $_ref); local $_; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | print {$self->{_dat_w_sock}->[0]} OUTPUT_W_RLA.$LF . '0'.$LF; | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | ▶ | MCE::Util::_sock_ready($_rdr, -1) if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 2 | chomp($_len = <$_rdr>); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | read $_rdr, $_, $_len; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | $_ref = chop $_; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 2 | ▶ | if ($_ref == 0) { ## scalar value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | my $_ret = ${ $self->{thaw}($_) }; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | ▶ | local $_ = $_ret; $_code->() if (ref $_code eq 'CODE'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | my $_tmp = $self->{freeze}(\$_) . '0'; | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | print {$_wtr} length($_tmp) . $LF . $_tmp; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | print {$self->{_dat_w_sock}->[0]} OUTPUT_R_NFY.$LF . '0'.$LF; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 2 | $self->{_relayed} = $_cid; | |||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | return $_ret; | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | elsif ($_ref == 1) { ## hash reference | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my %_ret = %{ $self->{thaw}($_) }; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | local $_ = { %_ret }; $_code->() if (ref $_code eq 'CODE'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $_tmp = $self->{freeze}($_) . '1'; | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | print {$_wtr} length($_tmp) . $LF . $_tmp; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | print {$self->{_dat_w_sock}->[0]} OUTPUT_R_NFY.$LF . '0'.$LF; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $self->{_relayed} = $_cid; | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | return %_ret; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | elsif ($_ref == 2) { ## array reference | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my @_ret = @{ $self->{thaw}($_) }; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | local $_ = [ @_ret ]; $_code->() if (ref $_code eq 'CODE'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $_tmp = $self->{freeze}($_) . '2'; | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | print {$_wtr} length($_tmp) . $LF . $_tmp; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | print {$self->{_dat_w_sock}->[0]} OUTPUT_R_NFY.$LF . '0'.$LF; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $self->{_relayed} = $_cid; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | return @_ret; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 24 | return; | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | ## Aliases. | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 10 | *relay_lock = \&relay_recv; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 10 | *relay_unlock = \&relay; | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | __END__ | ||||||||||||||||||||||||||||||||||||||||||