| 1 | package Linux::Event::Loop; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 181 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 181 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 181 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 181 | our $VERSION = '0.119'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 181 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 181 | ▶ | use Errno (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 181 | ▶ | use Hash::Util::FieldHash qw(fieldhash); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 181 | ▶ | use Scalar::Util qw(blessed refaddr weaken); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 181 | ▶ | use utf8 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 181 | require XSLoader; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 181 | XSLoader::load(__PACKAGE__, $VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 181 | require Linux::Event::Loop::Introspection; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 181 | our @ISA = ('Linux::Event::Loop::Introspection'); | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 181 | fieldhash my %DEFER_STATE; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 181 | fieldhash my %DEFER_FORK_STATE; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 181 | our $FORK_DRIVER_FRAME; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 181 | my $DEFER_CALLBACK_BATCH = 1024; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # Native drivers are private XS entry points. The public Perl boundary does | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # not retain XS coderefs across interpreter clones. | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 19 | ▶ | sub _fork_write_all ($fh, $bytes) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fork_write_all: called CC=6 SCAR=19.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 19 | my $offset = 0; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 19 | ▶ | while ($offset < length($bytes)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 19 | my $written = syswrite($fh, $bytes, length($bytes) - $offset, $offset); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 19 | ▶ | next if !defined($written) && $! == Errno::EINTR(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $written and $! == 4
MC/DC0%0/2
not defined $written and $! == 4
not defined $written
$! == 4
Truth table33%1/3
not(A) and B
A= not defined $writtenB= $! == 4
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 19 | ▶ | die "fork(): handshake write failed: $!\n" if !defined $written; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 19 | ▶ | die "fork(): handshake write returned zero bytes\n" if !$written; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 19 | $offset += $written; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 19 | return; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 22 | ▶ | sub _fork_read_exact ($fh, $length) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fork_read_exact: called CC=6 SCAR=18.8
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 22 | my $bytes = ''; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 22 | ▶ | while (length($bytes) < $length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 22 | my $chunk = ''; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 22 | my $read = sysread($fh, $chunk, $length - length($bytes)); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 22 | ▶ | next if !defined($read) && $! == Errno::EINTR(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $read and $! == 4
MC/DC0%0/2
not defined $read and $! == 4
not defined $read
$! == 4
Truth table33%1/3
not(A) and B
A= not defined $readB= $! == 4
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 22 | ▶ | die "fork(): handshake read failed: $!\n" if !defined $read; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 22 | ▶ | return undef if !$read; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 22 | $bytes .= $chunk; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 22 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub _fork_child_failure ($fh, $error) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fork_child_failure: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $error = "$error"; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $error = "child reconstruction failed\n" if $error eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | utf8::encode($error) if utf8::is_utf8($error); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $error = substr($error, 0, 1_048_576); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | eval { _fork_write_all($fh, 'E' . pack('N', length($error)) . $error); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | POSIX::_exit(255); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub _fork_child_reset_deferred ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fork_child_reset_deferred: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $state = delete $DEFER_STATE{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $state->_fork_child_drop if $state; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 27 | ▶ | sub fork ($self, %option) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fork: called CC=42 SCAR=54.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 27 | $self->_assert_owner_native('fork'); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 27 | ▶ | croak 'fork(): Loop must be quiescent and cannot fork during dispatch' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | if $self->running; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 26 | my %known = map { $_ => 1 } qw(share clone move); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 26 | my @unknown = sort grep { !$known{$_} } keys %option; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 26 | ▶ | croak 'fork(): unknown options: ' . join(', ', @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 25 | my %disposition; | |||||||||||||||||||||||||||||||||||||||||
| 79 | my %selected; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 25 | for my $mode (qw(share clone move)) { | |||||||||||||||||||||||||||||||||||||||||
| 81 | 73 | ▶ | my $list = exists($option{$mode}) ? $option{$mode} : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 73 | ▶ | croak "fork(): $mode must be an array reference" if ref($list) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 72 | for my $object (@$list) { | |||||||||||||||||||||||||||||||||||||||||
| 84 | 16 | ▶ | croak "fork(): $mode entries must be resource objects" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | if !blessed($object); | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 16 | my $id = refaddr($object); | |||||||||||||||||||||||||||||||||||||||||
| 87 | croak 'fork(): a resource may appear in only one disposition list' | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 16 | ▶ | if $selected{$id}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 15 | ▶ | croak "fork(): $mode resource is not current in this Loop" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | if !$self->has($object); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 15 | $disposition{$id} = $mode; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 23 | my $objects = $self->objects; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 23 | for my $object (@$objects) { | |||||||||||||||||||||||||||||||||||||||||
| 97 | 18 | ▶ | my $mode = $disposition{ refaddr($object) } // 'drop'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$disposition{builtin::refaddr($object)} // "drop"
MC/DC100%1/1
$disposition{builtin::refaddr($object)} // "drop"
$disposition{builtin::refaddr($object)}
Truth table100%2/2
A
A= $disposition{builtin::refaddr($object)}
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 18 | ▶ | croak 'fork(): resource does not implement fork disposition hooks' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$object->can("_fork_preflight") and $object->can("_fork_child_drop")
MC/DC0%0/2
$object->can("_fork_preflight") and $object->can("_fork_child_drop")
$object->can("_fork_preflight")
$object->can("_fork_child_drop")
Truth table33%1/3
A and B
A= $object->can("_fork_preflight")B= $object->can("_fork_child_drop")
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | if !$object->can('_fork_preflight') || !$object->can('_fork_child_drop'); | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 18 | $object->_fork_preflight($mode, $self); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 15 | ▶ | croak "fork(): resource does not implement child '$mode' disposition" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mode ne "drop" and not $object->can("_fork_child_$mode")
MC/DC0%0/2
$mode ne "drop" and not $object->can("_fork_child_$mode")
$mode ne "drop"
not $object->can("_fork_child_$mode")
Truth table66%2/3
A and not(B)
A= $mode ne "drop"B= not $object->can("_fork_child_$mode")
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | if $mode ne 'drop' && !$object->can("_fork_child_$mode"); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 15 | ▶ | croak 'fork(): moved resource does not implement parent disposition' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mode eq "move" and not $object->can("_fork_parent_move")
MC/DC0%0/2
$mode eq "move" and not $object->can("_fork_parent_move")
$mode eq "move"
not $object->can("_fork_parent_move")
Truth table66%2/3
A and not(B)
A= $mode eq "move"B= not $object->can("_fork_parent_move")
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | if $mode eq 'move' && !$object->can('_fork_parent_move'); | ||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | require Linux::Event::_Resolver; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 20 | Linux::Event::_Resolver->_fork_prepare_loop($self); | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 20 | require Socket; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 20 | ▶ | socketpair(my $parent_channel, my $child_channel, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | Socket::AF_UNIX(), Socket::SOCK_STREAM(), Socket::PF_UNSPEC()) | ||||||||||||||||||||||||||||||||||||||||||
| 113 | or croak "fork(): socketpair failed: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 20 | my $pid = CORE::fork(); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 20 | ▶ | if (!defined $pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $errno = 0 + $!; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | close $parent_channel; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | close $child_channel; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $! = $errno; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 20 | ▶ | if ($pid == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | close $parent_channel; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->_fork_child_reset; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $self->reset_stats; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->_fork_child_reset_deferred; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $self->_fork_child_reset_deferred_forks; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | require Linux::Event::Kernel::Signal; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | Linux::Event::Kernel::Signal->_fork_child_drop_loop($self); | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | for my $object (@$objects) { | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $mode = $disposition{ refaddr($object) } // 'drop'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$disposition{builtin::refaddr($object)} // "drop"
MC/DC0%0/1
$disposition{builtin::refaddr($object)} // "drop"
$disposition{builtin::refaddr($object)}
Truth table0%0/2
A
A= $disposition{builtin::refaddr($object)}
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $method = $mode eq 'drop' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | ? '_fork_child_drop' : "_fork_child_$mode"; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $object->$method($self); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 141 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | _fork_child_failure($child_channel, $@) if !$ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $ready = eval { _fork_write_all($child_channel, 'R'); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | _fork_child_failure($child_channel, $@) if !$ready; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $commit = eval { _fork_read_exact($child_channel, 1) }; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ($@ || !defined($commit) || $commit ne 'C') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$@ or not defined $commit or $commit ne "C"
$@ or not defined $commit
MC/DC0%0/3
$@ or not defined $commit or $commit ne "C"
$@
not defined $commit
$commit ne "C"
Truth table0%0/4
A or not(B) or C
A= $@B= not defined $commitC= $commit ne "C"
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | POSIX::_exit(255); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | close $child_channel; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 20 | close $child_channel; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 20 | my $status = eval { _fork_read_exact($parent_channel, 1) }; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 20 | ▶ | if ($@ || !defined $status) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or not defined $status
MC/DC0%0/2
$@ or not defined $status
$@
not defined $status
Truth table33%1/3
A or not(B)
A= $@B= not defined $status
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $error = $@ || "fork(): child reconstruction channel closed\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || "fork(): child reconstruction channel closed\n"
MC/DC0%0/1
$@ || "fork(): child reconstruction channel closed\n"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | waitpid($pid, 0); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | close $parent_channel; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | die $error; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 20 | ▶ | if ($status eq 'E') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | my $length_bytes = _fork_read_exact($parent_channel, 4); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | my $length = defined($length_bytes) ? unpack('N', $length_bytes) : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | my $message = $length ? _fork_read_exact($parent_channel, $length) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | waitpid($pid, 0); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | close $parent_channel; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | ▶ | $message //= 'child reconstruction failed'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$message //= "child reconstruction failed"
MC/DC0%0/1
$message //= "child reconstruction failed"
$message
Truth table50%1/2
A
A= $message
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | croak "fork(): $message"; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 19 | ▶ | if ($status ne 'R') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | waitpid($pid, 0); | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | close $parent_channel; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | croak 'fork(): invalid child reconstruction handshake'; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 19 | my $moved = eval { | |||||||||||||||||||||||||||||||||||||||||
| 179 | 19 | for my $object (@$objects) { | |||||||||||||||||||||||||||||||||||||||||
| 180 | 13 | ▶ | next if ($disposition{ refaddr($object) } // '') ne 'move'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$disposition{builtin::refaddr($object)} // ""
MC/DC100%1/1
$disposition{builtin::refaddr($object)} // ""
$disposition{builtin::refaddr($object)}
Truth table100%2/2
A
A= $disposition{builtin::refaddr($object)}
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | $object->_fork_parent_move($pid); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 19 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 184 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 19 | ▶ | if (!$moved) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | my $error = $@ || "fork(): parent move disposition failed\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || "fork(): parent move disposition failed\n"
MC/DC0%0/1
$@ || "fork(): parent move disposition failed\n"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | eval { _fork_write_all($parent_channel, 'A'); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | waitpid($pid, 0); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | close $parent_channel; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | die $error; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 19 | _fork_write_all($parent_channel, 'C'); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 19 | close $parent_channel; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 19 | return $pid; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 203201 | ▶ | sub add ($self, $object) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 203201 | ▶ | croak 'add(): object must support loop attachment' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($object) and $object->can("_attach_to_loop")
MC/DC50%1/2
builtin::blessed($object) and $object->can("_attach_to_loop")
builtin::blessed($object)
$object->can("_attach_to_loop")
Truth table66%2/3
A and B
A= builtin::blessed($object)B= $object->can("_attach_to_loop")
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | if !blessed($object) || !$object->can('_attach_to_loop'); | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 203200 | $object->_attach_to_loop($self); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 203192 | return $object; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 1055 | ▶ | sub _defer_state ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_defer_state: called CC=4 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 1055 | ▶ | return $DEFER_STATE{$self} if $DEFER_STATE{$self}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 18 | require Linux::Event::Kernel::Event; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 18 | my $fd = Linux::Event::Kernel::Event::_new_fd(); | |||||||||||||||||||||||||||||||||||||||||
| 209 | 18 | my $state = bless { | |||||||||||||||||||||||||||||||||||||||||
| 210 | fd => $fd, | ||||||||||||||||||||||||||||||||||||||||||
| 211 | queue => [], | ||||||||||||||||||||||||||||||||||||||||||
| 212 | pending => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 213 | signaled => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 214 | }, 'Linux::Event::Loop::_DeferService'; | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 18 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 217 | $self->watch( | ||||||||||||||||||||||||||||||||||||||||||
| 218 | fd => $fd, | ||||||||||||||||||||||||||||||||||||||||||
| 219 | _internal => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 25 | ▶ | read => sub { $state->_dispatch }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | error => sub { die "Linux::Event defer event source failed\n" }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 18 | no_args => 1, | |||||||||||||||||||||||||||||||||||||||||
| 223 | lean => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 224 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 18 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 226 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 18 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $close_fd = delete $state->{fd}; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | eval { Linux::Event::Kernel::Event::_close_fd($close_fd); 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | if defined $close_fd; | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | die $error; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 18 | $DEFER_STATE{$self} = $state; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 18 | return $state; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 1056 | ▶ | sub defer ($self, $callback) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defer: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 1056 | $self->_assert_owner_native('defer'); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 1056 | ▶ | croak 'defer(): callback must be a coderef' if ref($callback) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 1055 | my $state = $self->_defer_state; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 1055 | my $deferred = bless { | |||||||||||||||||||||||||||||||||||||||||
| 244 | state => $state, | ||||||||||||||||||||||||||||||||||||||||||
| 245 | callback => $callback, | ||||||||||||||||||||||||||||||||||||||||||
| 246 | active => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | }, 'Linux::Event::_Deferred'; | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 1055 | weaken($deferred->{state}); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 1055 | $state->_enqueue($deferred); | |||||||||||||||||||||||||||||||||||||||||
| 250 | 1055 | return $deferred; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 25 | ▶ | sub _deferred_count ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deferred_count: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 25 | my $state = $DEFER_STATE{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 25 | ▶ | return $state ? $state->{pending} : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 25 | ▶ | sub _deferred_fd ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deferred_fd: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 25 | my $state = $DEFER_STATE{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 25 | ▶ | return $state ? $state->{fd} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | # A deferred fork cannot execute in a normal defer() callback: that callback | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # still runs inside the native driver. The defer eventfd only asks the driver | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # to exit. We perform the managed fork after its XS frame has unwound. | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 13 | ▶ | sub defer_fork ($self, %option) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defer_fork: called CC=10 SCAR=23.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 13 | $self->_assert_owner_native('defer_fork'); | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 13 | my %known = map { $_ => 1 } | |||||||||||||||||||||||||||||||||||||||||
| 271 | qw(share clone move on_parent on_child on_error); | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 13 | my @unknown = sort grep { !$known{$_} } keys %option; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 13 | ▶ | croak 'defer_fork(): unknown options: ' . join(', ', @unknown) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | if @unknown; | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 12 | for my $mode (qw(share clone move)) { | |||||||||||||||||||||||||||||||||||||||||
| 277 | 36 | ▶ | next if !exists $option{$mode}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | croak "defer_fork(): $mode must be an array reference" | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | ▶ | if ref($option{$mode}) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 11 | for my $callback (qw(on_parent on_child on_error)) { | |||||||||||||||||||||||||||||||||||||||||
| 282 | 31 | ▶ | next if !exists $option{$callback}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | croak "defer_fork(): $callback must be a coderef" | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 18 | ▶ | if ref($option{$callback}) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 10 | ▶ | my $state = $DEFER_FORK_STATE{$self} //= { queue => [], pending => 0 }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$DEFER_FORK_STATE{$self} //= {"queue", [], "pending", 0}
MC/DC100%1/1
$DEFER_FORK_STATE{$self} //= {"queue", [], "pending", 0}
$DEFER_FORK_STATE{$self}
Truth table100%2/2
A
A= $DEFER_FORK_STATE{$self}
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | my $request = bless { | ||||||||||||||||||||||||||||||||||||||||||
| 289 | state => $state, | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 3 | options => { map { $_ => $option{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 291 | 30 | grep { exists $option{$_} } qw(share clone move) }, | |||||||||||||||||||||||||||||||||||||||||
| 292 | on_parent => delete $option{on_parent}, | ||||||||||||||||||||||||||||||||||||||||||
| 293 | on_child => delete $option{on_child}, | ||||||||||||||||||||||||||||||||||||||||||
| 294 | on_error => delete $option{on_error}, | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 10 | active => 1, | |||||||||||||||||||||||||||||||||||||||||
| 296 | }, 'Linux::Event::_DeferredFork'; | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 10 | weaken($request->{state}); | |||||||||||||||||||||||||||||||||||||||||
| 298 | 10 | push @{ $state->{queue} }, $request; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 10 | $state->{pending}++; | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | # A wakeup also handles requests scheduled while no driver is running, | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # and makes requests queued by on_parent wait for another Loop turn. | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 10 | my $weak_loop = $self; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 10 | my $weak_request = $request; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 10 | weaken($weak_loop); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 10 | weaken($weak_request); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 10 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 308 | 7 | ▶ | $self->defer(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 7 | ▶ | my $loop = $weak_loop // return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$weak_loop // (return)
MC/DC0%0/1
$weak_loop // (return)
$weak_loop
Truth table50%1/2
A
A= $weak_loop
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 7 | ▶ | my $pending = $weak_request // return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$weak_request // (return)
MC/DC0%0/1
$weak_request // (return)
$weak_request
Truth table50%1/2
A
A= $weak_request
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | $loop->_stop_native | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 7 | ▶ | if $pending->{active} && $loop->running; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pending->{"active"} and $loop->running
MC/DC50%1/2
$pending->{"active"} and $loop->running
$pending->{"active"}
$loop->running
Truth table66%2/3
A and B
A= $pending->{"active"}B= $loop->running
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 10 | }); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 315 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 10 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | pop @{ $state->{queue} }; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $state->{pending}--; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $request->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | delete @$request{qw(options on_parent on_child on_error)}; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | die $error; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 10 | return $request; | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub _fork_child_reset_deferred_forks ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fork_child_reset_deferred_forks: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $state = delete $DEFER_FORK_STATE{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | return if !$state; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | for my $request (@{ $state->{queue} }) { | |||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | next if !$request; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $request->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | delete @$request{qw(options on_parent on_child on_error)}; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $state->{queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $state->{pending} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | # Driver frames are dynamically scoped, never stored on a Loop. In particular, | ||||||||||||||||||||||||||||||||||||||||||
| 341 | # this avoids retaining Loop-owned objects across Perl ithread cloning. | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 269 | ▶ | sub _current_fork_driver ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_current_fork_driver: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 269 | my $frame = $FORK_DRIVER_FRAME; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 269 | ▶ | while ($frame) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 266 | ▶ | return $frame if refaddr($frame->{loop}) == refaddr($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $frame = $frame->{parent}; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 661 | ▶ | sub _drain_deferred_forks ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_drain_deferred_forks: called CC=16 SCAR=30.1
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 661 | my $state = $DEFER_FORK_STATE{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 661 | ▶ | return 0 if !$state || !$state->{pending}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$state and $state->{"pending"}
MC/DC100%2/2
$state and $state->{"pending"}
$state
$state->{"pending"}
Truth table100%3/3
A and B
A= $stateB= $state->{"pending"}
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | # Freeze the eligible set: requests added from completion callbacks wait | ||||||||||||||||||||||||||||||||||||||||||
| 356 | # for the next driver turn, rather than recursively forking here. | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 8 | my $eligible = scalar @{ $state->{queue} }; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 8 | my $processed = 0; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 8 | for (1 .. $eligible) { | |||||||||||||||||||||||||||||||||||||||||
| 360 | 9 | my $driver = $self->_current_fork_driver; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 9 | ▶ | last if $driver && $driver->{user_stop}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$driver and $driver->{"user_stop"}
MC/DC0%0/2
$driver and $driver->{"user_stop"}
$driver
$driver->{"user_stop"}
Truth table33%1/3
A and B
A= $driverB= $driver->{"user_stop"}
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 9 | my $request = shift @{ $state->{queue} }; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 9 | ▶ | next if !$request || !$request->{active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$request and $request->{"active"}
MC/DC0%0/2
$request and $request->{"active"}
$request
$request->{"active"}
Truth table33%1/3
A and B
A= $requestB= $request->{"active"}
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 9 | $request->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 9 | $state->{pending}--; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 9 | $processed++; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 9 | my $options = delete $request->{options}; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 9 | my $on_parent = delete $request->{on_parent}; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 9 | my $on_child = delete $request->{on_child}; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 9 | my $on_error = delete $request->{on_error}; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 9 | my $pid; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 9 | my $ok = eval { $pid = $self->fork(%$options); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 9 | ▶ | if (!$ok || !defined $pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ok and defined $pid
MC/DC50%1/2
$ok and defined $pid
$ok
defined $pid
Truth table66%2/3
A and B
A= $okB= defined $pid
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 2 | ▶ | my $error = !$ok ? $@ : "defer_fork(): fork failed: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | ▶ | if ($on_error) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | $on_error->($error); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | die $error; | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 7 | ▶ | if ($pid == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | # fork() has discarded the inherited queue in this child. | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | $on_child->() if $on_child; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | return $processed; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 7 | ▶ | $on_parent->($pid) if $on_parent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 8 | ▶ | $state->{queue} = [] if !$state->{pending}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 8 | return $processed; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 260 | ▶ | sub stop ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | # A user stop must not be mistaken for defer_fork's internal wakeup. | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 260 | my $driver = $self->_current_fork_driver; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 260 | ▶ | $driver->{user_stop} = 1 if $driver; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 260 | $self->_stop_native(); | |||||||||||||||||||||||||||||||||||||||||
| 400 | 260 | return; | |||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 238 | ▶ | sub run ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 238 | my $driver = { | |||||||||||||||||||||||||||||||||||||||||
| 405 | loop => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 406 | parent => $FORK_DRIVER_FRAME, | ||||||||||||||||||||||||||||||||||||||||||
| 407 | user_stop => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 408 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 238 | local $FORK_DRIVER_FRAME = $driver; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 238 | $self->_drain_deferred_forks; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 238 | ▶ | while (!$driver->{user_stop}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 238 | $self->_run_native(); | |||||||||||||||||||||||||||||||||||||||||
| 413 | 231 | ▶ | last if $driver->{user_stop}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 3 | ▶ | last if !$self->_drain_deferred_forks; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 231 | return; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 91 | ▶ | sub run_for ($self, $seconds) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_for: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 91 | require Time::HiRes; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 91 | my $started = Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC()); | |||||||||||||||||||||||||||||||||||||||||
| 422 | 91 | my $driver = { | |||||||||||||||||||||||||||||||||||||||||
| 423 | loop => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 424 | parent => $FORK_DRIVER_FRAME, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | user_stop => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 426 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 91 | local $FORK_DRIVER_FRAME = $driver; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 91 | $self->_drain_deferred_forks; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 91 | my $first = 1; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 91 | ▶ | while (!$driver->{user_stop}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 91 | my $elapsed = Time::HiRes::clock_gettime( | |||||||||||||||||||||||||||||||||||||||||
| 432 | Time::HiRes::CLOCK_MONOTONIC()) - $started; | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 91 | my $remaining = $seconds - $elapsed; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 91 | ▶ | last if !$first && $remaining <= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $first and $remaining <= 0
MC/DC0%0/2
not $first and $remaining <= 0
not $first
$remaining <= 0
Truth table33%1/3
not(A) and B
A= not $firstB= $remaining <= 0
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | # The first native entry still validates all run_for arguments. | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 91 | ▶ | $self->_run_for_native( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | $remaining > 0 ? $remaining : $seconds); | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 80 | $first = 0; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 80 | ▶ | last if $driver->{user_stop}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 56 | ▶ | last if !$self->_drain_deferred_forks; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 80 | return; | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 129 | ▶ | sub run_once ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_once: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 129 | my $driver = { | |||||||||||||||||||||||||||||||||||||||||
| 447 | loop => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 448 | parent => $FORK_DRIVER_FRAME, | ||||||||||||||||||||||||||||||||||||||||||
| 449 | user_stop => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 450 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 129 | local $FORK_DRIVER_FRAME = $driver; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 129 | $self->_drain_deferred_forks; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 129 | ▶ | return 0 if $driver->{user_stop}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 129 | my $n = $self->_run_once_native(@args); | |||||||||||||||||||||||||||||||||||||||||
| 455 | 122 | ▶ | $self->_drain_deferred_forks if !$driver->{user_stop}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 122 | return $n; | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 12 | ▶ | sub poll ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
poll: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 12 | my $driver = { | |||||||||||||||||||||||||||||||||||||||||
| 461 | loop => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 462 | parent => $FORK_DRIVER_FRAME, | ||||||||||||||||||||||||||||||||||||||||||
| 463 | user_stop => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 464 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 12 | local $FORK_DRIVER_FRAME = $driver; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 12 | $self->_drain_deferred_forks; | |||||||||||||||||||||||||||||||||||||||||
| 467 | 12 | ▶ | return 0 if $driver->{user_stop}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 12 | my $n = $self->_poll_native(); | |||||||||||||||||||||||||||||||||||||||||
| 469 | 11 | ▶ | $self->_drain_deferred_forks if !$driver->{user_stop}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 11 | return $n; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | sub CLONE_SKIP ($class) { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLONE_SKIP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | package Linux::Event::Loop::_DeferService; | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 1064 | ▶ | sub _signal ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_signal: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | 1064 | ▶ | return if $self->{signaled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 28 | Linux::Event::Kernel::Event::_signal_fd($self->{fd}, 1); | |||||||||||||||||||||||||||||||||||||||||
| 480 | 28 | $self->{signaled} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 28 | return; | |||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 1055 | ▶ | sub _enqueue ($self, $deferred) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enqueue: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 1055 | push @{ $self->{queue} }, $deferred; | |||||||||||||||||||||||||||||||||||||||||
| 486 | 1055 | $self->{pending}++; | |||||||||||||||||||||||||||||||||||||||||
| 487 | 1055 | my $ok = eval { $self->_signal; 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 1055 | ▶ | return if $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | pop @{ $self->{queue} }; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | $self->{pending}--; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | $deferred->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | delete $deferred->{callback}; | |||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | die $error; | |||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | ▶ | sub _cancel ($self, $deferred) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cancel: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | ▶ | return if !$deferred->{active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | $deferred->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | delete $deferred->{callback}; | |||||||||||||||||||||||||||||||||||||||||
| 502 | 1 | ▶ | $self->{pending}-- if $self->{pending}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 1 | ▶ | $self->{queue} = [] if !$self->{pending}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | sub _fork_child_drop ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fork_child_drop: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | ▶ | for my $deferred (@{ $self->{queue} // [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"queue"} // []
MC/DC0%0/1
$self->{"queue"} // []
$self->{"queue"}
Truth table0%0/2
A
A= $self->{"queue"}
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | next if !$deferred; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | $deferred->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | delete $deferred->{callback}; | |||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | $self->{queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | $self->{pending} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $self->{signaled} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | my $fd = delete $self->{fd}; | |||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | eval { Linux::Event::Kernel::Event::_close_fd($fd); 1 } if defined $fd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 25 | ▶ | sub _dispatch ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dispatch: called CC=14 SCAR=27.0
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 25 | ▶ | return if !defined $self->{fd}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 25 | Linux::Event::Kernel::Event::_drain_fd($self->{fd}); | |||||||||||||||||||||||||||||||||||||||||
| 524 | 25 | $self->{signaled} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 25 | my $eligible = scalar @{ $self->{queue} }; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 25 | ▶ | $eligible = $DEFER_CALLBACK_BATCH | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | if $eligible > $DEFER_CALLBACK_BATCH; | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 25 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 531 | 25 | for (1 .. $eligible) { | |||||||||||||||||||||||||||||||||||||||||
| 532 | 1052 | my $deferred = shift @{ $self->{queue} }; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 1052 | ▶ | next if !$deferred || !$deferred->{active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$deferred and $deferred->{"active"}
MC/DC50%1/2
$deferred and $deferred->{"active"}
$deferred
$deferred->{"active"}
Truth table66%2/3
A and B
A= $deferredB= $deferred->{"active"}
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 1051 | $deferred->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 1051 | ▶ | $self->{pending}-- if $self->{pending}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 1051 | my $callback = delete $deferred->{callback}; | |||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 1051 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 540 | 1051 | my $ok = eval { $callback->(); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 1051 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 1 | ▶ | $error = $@ || "deferred callback failed\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$@ || "deferred callback failed\n"
MC/DC0%0/1
$@ || "deferred callback failed\n"
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | last; | |||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 25 | ▶ | if (!$self->{pending}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 16 | $self->{queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 9 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 552 | 9 | my $ok = eval { $self->_signal; 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 9 | ▶ | $error = $@ || "defer event source signal failed\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$ok or defined $error
$@ || "defer event source signal failed\n"
MC/DC0%0/2
$ok or defined $error
$ok
defined $error
MC/DC0%0/1
$@ || "defer event source signal failed\n"
$@
Truth table33%1/3
A or B
A= $okB= defined $error
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | if !$ok && !defined $error; | ||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 25 | ▶ | die $error if defined $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 24 | return; | |||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | sub CLONE_SKIP ($class) { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLONE_SKIP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 18 | ▶ | sub DESTROY ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 18 | ▶ | for my $deferred (@{ $self->{queue} // [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"queue"} // []
MC/DC0%0/1
$self->{"queue"} // []
$self->{"queue"}
Truth table50%1/2
A
A= $self->{"queue"}
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | 3 | ▶ | next if !$deferred; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 3 | $deferred->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 567 | 3 | delete $deferred->{callback}; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 18 | $self->{queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 570 | 18 | $self->{pending} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 18 | my $fd = delete $self->{fd}; | |||||||||||||||||||||||||||||||||||||||||
| 572 | 18 | ▶ | eval { Linux::Event::Kernel::Event::_close_fd($fd); 1 } if defined $fd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | 18 | return; | |||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | package Linux::Event::_Deferred; | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | 2 | ▶ | sub cancel ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cancel: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | 2 | ▶ | return $self if !$self->{active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | 1 | my $state = $self->{state}; | |||||||||||||||||||||||||||||||||||||||||
| 581 | 1 | ▶ | if ($state) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | 1 | $state->_cancel($self); | |||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||
| 584 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | $self->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | delete $self->{callback}; | |||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 10 | ▶ | sub is_active ($self) { !!$self->{active} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_active: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | sub CLONE_SKIP ($class) { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLONE_SKIP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | package Linux::Event::_DeferredFork; | ||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | 2 | ▶ | sub cancel ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cancel: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 2 | ▶ | return $self if !$self->{active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | $self->{active} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | delete @$self{qw(options on_parent on_child on_error)}; | |||||||||||||||||||||||||||||||||||||||||
| 600 | 1 | my $state = $self->{state}; | |||||||||||||||||||||||||||||||||||||||||
| 601 | 1 | ▶ | if ($state && $state->{pending}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$state and $state->{"pending"}
MC/DC0%0/2
$state and $state->{"pending"}
$state
$state->{"pending"}
Truth table33%1/3
A and B
A= $stateB= $state->{"pending"}
| |||||||||||||||||||||||||||||||||||||||||||
| 602 | 1 | $state->{pending}--; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 1 | ▶ | $state->{queue} = [] if !$state->{pending}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||
| 605 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 6 | ▶ | sub is_active ($self) { !!$self->{active} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_active: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | sub CLONE_SKIP ($class) { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLONE_SKIP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | package Linux::Event::_Registration; | ||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | ▶ | sub CLONE_SKIP ($class) { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLONE_SKIP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | package Linux::Event::Loop; | ||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 181 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | __END__ | ||||||||||||||||||||||||||||||||||||||||||