| 1 | ############################################################################### | ||||||||||||||||||||||||||||
| 2 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 3 | ## Queue-like and two-way communication capability. | ||||||||||||||||||||||||||||
| 4 | ## | ||||||||||||||||||||||||||||
| 5 | ############################################################################### | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package MCE::Channel; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 15 | ▶ | no warnings qw( uninitialized once ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 15 | our $VERSION = '1.904'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | ## no critic (BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||||||||||
| 17 | ## no critic (TestingAndDebugging::ProhibitNoStrict) | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 15 | ▶ | use if $^O eq 'MSWin32', 'threads'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 15 | ▶ | use if $^O eq 'MSWin32', 'threads::shared'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 15 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 15 | $Carp::Internal{ (__PACKAGE__) }++; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 15 | my ( $freeze, $thaw ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 15 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=6 SCAR=19.4
| |||||||||||||||||||||||||||||
| 29 | 15 | ▶ | if ( $] ge '5.008008' && ! $INC{'PDL.pm'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$] ge "5.008008" and not $INC{"PDL.pm"}
MC/DC0%0/2
$] ge "5.008008" and not $INC{"PDL.pm"}
$] ge "5.008008"
not $INC{"PDL.pm"}
Truth table33%1/3
A and not(B)
A= $] ge "5.008008"B= not $INC{"PDL.pm"}
| |||||||||||||||||||||||||||||
| 30 | 15 | local $@; | |||||||||||||||||||||||||||
| 31 | 15 | ▶ | eval 'use Sereal::Encoder 3.015; use Sereal::Decoder 3.015;'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 15 | ▶ | if ( ! $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 15 | my $encoder_ver = int( Sereal::Encoder->VERSION() ); | |||||||||||||||||||||||||||
| 34 | 15 | my $decoder_ver = int( Sereal::Decoder->VERSION() ); | |||||||||||||||||||||||||||
| 35 | 15 | ▶ | if ( $encoder_ver - $decoder_ver == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 15 | $freeze = \&Sereal::Encoder::encode_sereal; | |||||||||||||||||||||||||||
| 37 | 15 | $thaw = \&Sereal::Decoder::decode_sereal; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 15 | ▶ | if ( ! defined $freeze ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | require Storable; | |||||||||||||||||||||||||||
| 44 | 0 | $freeze = \&Storable::freeze; | |||||||||||||||||||||||||||
| 45 | 0 | $thaw = \&Storable::thaw; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 15 | ▶ | use MCE::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 15 | ▶ | my $tid = $INC{'threads.pm'} ? threads->tid() : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 23 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 23 | my ( $class, %argv ) = @_; | |||||||||||||||||||||||||||
| 55 | 23 | ▶ | my $impl = defined( $argv{impl} ) ? ucfirst( lc $argv{impl} ) : 'Mutex'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Replace 'fast' with 'Fast' in the implementation value. | ||||||||||||||||||||||||||||
| 58 | 23 | $impl =~ s/fast/Fast/; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 23 | ▶ | $impl = 'Threads' if ( $impl eq 'Mutex' && $^O eq 'MSWin32' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$impl eq "Mutex" and $^O eq "MSWin32"
MC/DC0%0/2
$impl eq "Mutex" and $^O eq "MSWin32"
$impl eq "Mutex"
$^O eq "MSWin32"
Truth table66%2/3
A and B
A= $impl eq "Mutex"B= $^O eq "MSWin32"
| |||||||||||||||||||||||||||||
| 61 | 23 | ▶ | $impl = 'ThreadsFast' if ( $impl eq 'MutexFast' && $^O eq 'MSWin32' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$impl eq "MutexFast" and $^O eq "MSWin32"
MC/DC0%0/2
$impl eq "MutexFast" and $^O eq "MSWin32"
$impl eq "MutexFast"
$^O eq "MSWin32"
Truth table66%2/3
A and B
A= $impl eq "MutexFast"B= $^O eq "MSWin32"
| |||||||||||||||||||||||||||||
| 62 | 23 | ▶ | $impl = 'Mutex' if ( $impl eq 'Threads' && $^O eq 'cygwin' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$impl eq "Threads" and $^O eq "cygwin"
MC/DC0%0/2
$impl eq "Threads" and $^O eq "cygwin"
$impl eq "Threads"
$^O eq "cygwin"
Truth table33%1/3
A and B
A= $impl eq "Threads"B= $^O eq "cygwin"
| |||||||||||||||||||||||||||||
| 63 | 23 | ▶ | $impl = 'MutexFast' if ( $impl eq 'ThreadsFast' && $^O eq 'cygwin' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$impl eq "ThreadsFast" and $^O eq "cygwin"
MC/DC0%0/2
$impl eq "ThreadsFast" and $^O eq "cygwin"
$impl eq "ThreadsFast"
$^O eq "cygwin"
Truth table33%1/3
A and B
A= $impl eq "ThreadsFast"B= $^O eq "cygwin"
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 23 | ▶ | eval "require MCE::Channel::$impl; 1;" || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | Carp::croak("Could not load Channel implementation '$impl': $@"); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 23 | my $pkg = 'MCE::Channel::'.$impl; | |||||||||||||||||||||||||||
| 69 | 15 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 23 | $pkg->new(%argv); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub CLONE { | ||||||||||||||||||||||||||
|
Subroutine
CLONE: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $tid = threads->tid if $INC{'threads.pm'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 16 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 79 | 16 | ▶ | my ( $pid, $self ) = ( $tid ? $$ .'.'. $tid : $$, @_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 16 | ▶ | if ( $self->{'init_pid'} && $self->{'init_pid'} eq $pid ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"init_pid"} and $self->{"init_pid"} eq $pid
MC/DC50%1/2
$self->{"init_pid"} and $self->{"init_pid"} eq $pid
$self->{"init_pid"}
$self->{"init_pid"} eq $pid
Truth table66%2/3
A and B
A= $self->{"init_pid"}B= $self->{"init_pid"} eq $pid
| |||||||||||||||||||||||||||||
| 82 | 13 | MCE::Util::_destroy_socks($self, qw(c_sock c2_sock p_sock p2_sock)); | |||||||||||||||||||||||||||
| 83 | 13 | delete($self->{c_mutex}), delete($self->{p_mutex}); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 16 | return; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 6 | ▶ | sub impl { | ||||||||||||||||||||||||||
|
Subroutine
impl: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 6 | ▶ | $_[0]->{'impl'} || 'Not defined'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 12 | ▶ | sub _get_freeze { $freeze; } | ||||||||||||||||||||||||||
|
Subroutine
_get_freeze: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 12 | ▶ | sub _get_thaw { $thaw; } | ||||||||||||||||||||||||||
|
Subroutine
_get_thaw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 12 | ▶ | sub _ended { | ||||||||||||||||||||||||||
|
Subroutine
_ended: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 97 | 12 | warn "WARNING: ($_[0]) called on a channel that has been 'end'ed\n"; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 12 | return; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 120 | ▶ | sub _read { | ||||||||||||||||||||||||||
|
Subroutine
_read: called CC=4 SCAR=18.7
| |||||||||||||||||||||||||||||
| 103 | 120 | my $bytes = MCE::Util::_sysread( $_[0], $_[1], my $len = $_[2] ); | |||||||||||||||||||||||||||
| 104 | 120 | my $read = $bytes; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 120 | ▶ | while ( $bytes && $read != $len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$bytes and $read != $len
MC/DC0%0/2
$bytes and $read != $len
$bytes
$read != $len
Truth table33%1/3
A and B
A= $bytesB= $read != $len
| |||||||||||||||||||||||||||||
| 107 | 0 | $bytes = MCE::Util::_sysread( $_[0], $_[1], $len - $read, length($_[1]) ); | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | $read += $bytes if $bytes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 120 | return; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 23 | ▶ | sub _pid { | ||||||||||||||||||||||||||
|
Subroutine
_pid: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 115 | 23 | ▶ | $tid ? $$ .'.'. $tid : $$; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 15 | 1; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||