blib/lib/Linux/Event/Wakeup.pm

filter: Statementstmt 91.3% 127 / 139 Branchbran 63.8% 46 / 72 Conditioncond 44.0% 26 / 59 MC/DCmcdc 9.6% 3 / 31 Subroutinesub 89.6% 26 / 29 Podpod 87.5% 7 / 8 totaltotal 69.5% 235 / 338 CC 60 SCAR 21.2
CC
60
Cov
74%
CLONE
30.0
DESTROY
18.1
signal
9.4
CRAP 8.3
« bench/run-callback-batching-fairness.pl ↑ Summary blib/lib/Linux/Event/Framer/Delimiter.pm »
1 package Linux::Event::Wakeup;
2 7 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 our $VERSION = '0.105';
7  
8 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Scalar::Util qw(refaddr weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 require Linux::Event::Loop;
13 7 require XSLoader;
14 7 XSLoader::load(__PACKAGE__, $VERSION);
15  
16 7 my %CLASS_DESCRIPTOR;
17 my %OWNER_STATE;
18 7 my %LIVE_HANDLE;
19 7 my $NEXT_ID = 1;
20 7 ▶my $MAX_INCREMENT = $Config::Config{uvsize} >= 8
Branch: 1 branch
BranchTrueFalseTotal
$Config::Config{'uvsize'} >= 8 ? : 7 0 7
21 ? '18446744073709551614' : '4294967295';
22  
23 44 ▶sub _decimal_greater_than ($value, $maximum) {
Subroutine _decimal_greater_than: called CC=4 SCAR=14.1
24 44 $value =~ s/\A0+//;
25 44 ▶ $value = '0' if $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "" 0 44 44
26 44 ▶ return 1 if length($value) > length($maximum);
Branch: 1 branch
BranchTrueFalseTotal
if length $value > length $maximum 0 44 44
27 44 ▶ return 0 if length($value) < length($maximum);
Branch: 1 branch
BranchTrueFalseTotal
if length $value < length $maximum 43 1 44
28 1 return $value gt $maximum;
29 }
30  
31 11 ▶sub _descriptor_for ($class) {
Subroutine _descriptor_for: called CC=5 SCAR=16.1
32 11 ▶ return $CLASS_DESCRIPTOR{$class} if exists $CLASS_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$class} 3 8 11
33 8 ▶ croak 'Linux::Event::Wakeup is an abstract base class'
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ 1 7 8
34 if $class eq __PACKAGE__;
35 7 ▶ croak "$class is not a Linux::Event::Wakeup subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 7 7
36 if !$class->isa(__PACKAGE__);
37 7 ▶ my $callback = $class->can('on_wakeup')
Condition100%2/2
$class->can("on_wakeup") // croak("$class must define on_wakeup()")
l!l
61
MC/DC100%1/1
$class->can("on_wakeup") // croak("$class must define on_wakeup()")
$class->can("on_wakeup")
Truth table100%2/2
A
A= $class->can("on_wakeup")
Aresult
11
00
38 // croak "$class must define on_wakeup()";
39 6 return $CLASS_DESCRIPTOR{$class} = { callback => $callback };
40 }
41  
42 11 ▶sub new ($class, %option) {
Subroutine new: called CC=8 SCAR=22.3
Pod undocumented
43 11 ▶ croak 'new(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 11 11
44 11 my $loop = delete $option{loop};
45 11 ▶ croak 'new(): loop must be an object implementing add() and watch()'
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch") 0 11 11
Condition44%4/9
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch")
!ll&&!rl&&r
740
ref $loop && $loop->can('add') && $loop->can('watch')
!ll&&!rl&&r
004
ref $loop and $loop->can("add")
!ll&&!rl&&r
004
MC/DC0%0/4
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch")
defined $loop ref $loop $loop->can("add") $loop->can('watch')
Truth table40%2/5
A and not(B and C && D)
A= defined $loopB= ref $loopC= $loop->can("add")D= $loop->can('watch')
ABCDresult
0XXX0
11110
10XX1
110X1
11101
46 if defined($loop) && (!ref($loop) || !$loop->can('add')
47 || !$loop->can('watch'));
48 11 my $data = delete $option{data};
49 11 ▶ croak 'new(): unknown options: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 11 11
50 if %option;
51 11 my $id = $NEXT_ID++;
52 11 my $self = bless {
53 id => $id,
54 fd => _new_fd(),
55 terminal => 0,
56 owner_pid => $$,
57 owner_interpreter => _interpreter_id(),
58 handle_interpreter => _interpreter_id(),
59 cloned_signal_handle => 0,
60 }, $class;
61 11 $LIVE_HANDLE{$id} = $self;
62 11 weaken($LIVE_HANDLE{$id});
63 11 $OWNER_STATE{$id} = bless {
64 descriptor => _descriptor_for($class),
65 loop => undef,
66 watcher => undef,
67 data => $data,
68 state => 'unattached',
69 }, 'Linux::Event::Wakeup::_OwnerState';
70 9 ▶ $loop->add($self) if defined $loop;
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop 4 5 9
71 9 return $self;
72 }
73  
74 99 ▶sub _assert_owner ($self, $method) {
Subroutine _assert_owner: called CC=4 SCAR=17.9
75 croak "$method(): Wakeup may be managed only by its creating interpreter"
76 if $self->{cloned_signal_handle}
77 || $self->{owner_pid} != $$
78 99 ▶ || $self->{owner_interpreter} != _interpreter_id();
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cloned_signal_handle"} or $self->{"owner_pid"} != $$ or $self->{"owner_interpreter"} != _interpreter_id() 0 99 99
Condition33%2/6
$self->{"cloned_signal_handle"} or $self->{"owner_pid"} != $$ or $self->{"owner_interpreter"} != _interpreter_id()
l!l&&r!l&&!r
0099
$self->{"cloned_signal_handle"} or $self->{"owner_pid"} != $$
l!l&&r!l&&!r
0099
MC/DC0%0/3
$self->{"cloned_signal_handle"} or $self->{"owner_pid"} != $$ or $self->{"owner_interpreter"} != _interpreter_id()
$self->{"cloned_signal_handle"} $self->{"owner_pid"} != $$ $self->{"owner_interpreter"} != _interpreter_id()
Truth table25%1/4
A or B or C
A= $self->{"cloned_signal_handle"}B= $self->{"owner_pid"} != $$C= $self->{"owner_interpreter"} != _interpreter_id()
ABCresult
1XX1
01X1
0011
0000
79 99 return;
80 }
81  
82 99 ▶sub _owner_state ($self, $method) {
Subroutine _owner_state: called CC=2 SCAR=7.2
83 99 $self->_assert_owner($method);
84 return $OWNER_STATE{ $self->{id} }
85 99 ▶ // croak "$method(): Wakeup owner state is unavailable";
Condition50%1/2
$OWNER_STATE{$self->{"id"}} // croak("$method(): Wakeup owner state is unavailable")
l!l
990
MC/DC0%0/1
$OWNER_STATE{$self->{"id"}} // croak("$method(): Wakeup owner state is unavailable")
$OWNER_STATE{$self->{"id"}}
Truth table50%1/2
A
A= $OWNER_STATE{$self->{"id"}}
Aresult
11
00
86 }
87  
88 11 ▶sub _attach_to_loop ($self, $loop) {
Subroutine _attach_to_loop: called CC=4 SCAR=14.4
89 11 ▶ croak 'add(): Wakeup is not unattached' if $self->{terminal};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"terminal"} 1 10 11
90 10 my $state = $self->_owner_state('add');
91 croak 'add(): Wakeup is not unattached'
92 10 ▶ if $state->{state} ne 'unattached' || $state->{loop};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"state"} ne "unattached" or $state->{"loop"} 0 10 10
Condition33%1/3
$state->{"state"} ne "unattached" or $state->{"loop"}
l!l&&r!l&&!r
0010
MC/DC0%0/2
$state->{"state"} ne "unattached" or $state->{"loop"}
$state->{"state"} ne "unattached" $state->{"loop"}
Truth table33%1/3
A or B
A= $state->{"state"} ne "unattached"B= $state->{"loop"}
ABresult
1X1
011
000
93 my $watcher = $loop->watch(
94 fd => $self->{fd},
95 _internal => 1,
96 28 ▶ read => sub { $self->_dispatch },
Subroutine __ANON__: called CC=1 SCAR=0.0
97 0 ▶ error => sub { die "Linux::Event Wakeup event source failed\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 10 no_args => 1,
99 lean => 1,
100 );
101 9 $state->{loop} = $loop;
102 9 $state->{state} = 'active';
103 9 $state->{watcher} = $watcher;
104 9 return $self;
105 }
106  
107 28 ▶sub _dispatch ($self) {
Subroutine _dispatch: called CC=3 SCAR=11.2
108 28 my $state = $self->_owner_state('dispatch');
109 28 ▶ return if $state->{state} ne 'active';
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"state"} ne "active" 0 28 28
110 28 my $count = _drain_fd($self->{fd});
111 28 ▶ return if !$count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 0 28 28
112 28 $state->{descriptor}{callback}->($self, $count);
113 27 return;
114 }
115  
116 47 ▶sub signal ($self, $increment = 1) {
Subroutine signal: called CC=9 SCAR=22.4
Pod documented
117 47 ▶ croak 'signal(): Wakeup is cancelled' if $self->{terminal};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"terminal"} 1 46 47
118 croak 'signal(): cloned Wakeup handle belongs to another interpreter'
119 46 ▶ if $self->{handle_interpreter} != _interpreter_id();
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"handle_interpreter"} != _interpreter_id() 0 46 46
120 46 ▶ croak 'signal(): increment must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $increment or ref $increment or not $increment =~ /\A\d+\z/u or $increment == 0 2 44 46
Condition66%6/9
not defined $increment or ref $increment or not $increment =~ /\A\d+\z/u or $increment == 0
l!l&&r!l&&!r
1144
not defined $increment or ref $increment or not $increment =~ /\A\d+\z/u
l!l&&r!l&&!r
0145
not defined $increment or ref $increment
l!l&&r!l&&!r
0046
MC/DC50%2/4
not defined $increment or ref $increment or not $increment =~ /\A\d+\z/u or $increment == 0
not defined $increment ref $increment not $increment =~ /\A\d+\z/u $increment == 0
Truth table60%3/5
not(A) or B or not(C) or D
A= not defined $incrementB= ref $incrementC= not $increment =~ /\A\d+\z/uD= $increment == 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
121 if !defined($increment) || ref($increment)
122 || $increment !~ /\A\d+\z/ || $increment == 0;
123 44 ▶ croak 'signal(): increment exceeds the supported eventfd range'
Branch: 1 branch
BranchTrueFalseTotal
if _decimal_greater_than("$increment", $MAX_INCREMENT) 1 43 44
124 if _decimal_greater_than("$increment", $MAX_INCREMENT);
125 43 _signal_fd($self->{fd}, 0 + $increment);
126 43 return $self;
127 }
128  
129 10 ▶sub cancel ($self) {
Subroutine cancel: called CC=4 SCAR=13.9
Pod documented
130 10 ▶ return $self if $self->{terminal};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"terminal"} 1 9 10
131 9 my $state = $self->_owner_state('cancel');
132 9 ▶ $state->{watcher}->cancel if $state->{watcher};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"watcher"} 9 0 9
133 9 $state->{watcher} = undef;
134 9 ▶ _close_fd(delete $self->{fd}) if defined $self->{fd};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fd"} 9 0 9
135 9 delete $LIVE_HANDLE{ $self->{id} };
136 9 $state->{loop} = undef;
137 9 $state->{data} = undef;
138 9 $state->{state} = 'cancelled';
139 9 delete $OWNER_STATE{ $self->{id} };
140 9 $self->{terminal} = 1;
141 9 return $self;
142 }
143  
144 20 ▶sub loop ($self) {
Subroutine loop: called CC=2 SCAR=6.9
Pod documented
145 20 ▶ return undef if $self->{terminal};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"terminal"} 1 19 20
146 19 return $self->_owner_state('loop')->{loop};
147 }
148 7 ▶sub state ($self) {
Subroutine state: called CC=2 SCAR=6.9
Pod documented
149 7 ▶ return 'cancelled' if $self->{terminal};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"terminal"} 1 6 7
150 6 return $self->_owner_state('state')->{state};
151 }
152 2 ▶sub is_active ($self) { $self->state eq 'active' }
Subroutine is_active: called CC=1 SCAR=0.0
Pod documented
153 18 ▶sub is_terminal ($self) { !!$self->{terminal} }
Subroutine is_terminal: called CC=1 SCAR=0.0
Pod documented
154  
155 27 ▶sub data ($self, @argument) {
Subroutine data: called CC=3 SCAR=11.4
Pod documented
156 27 ▶ croak 'data(): Wakeup is cancelled' if $self->{terminal};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"terminal"} 0 27 27
157 27 my $state = $self->_owner_state('data');
158 27 ▶ $state->{data} = $argument[0] if @argument;
Branch: 1 branch
BranchTrueFalseTotal
if @argument 0 27 27
159 27 return $state->{data};
160 }
161  
162 18 ▶sub _objects_for_loop ($class, $loop) {
Subroutine _objects_for_loop: called CC=7 SCAR=21.5
163 18 my @object;
164 18 for my $id (keys %LIVE_HANDLE) {
165 16 ▶ my $object = $LIVE_HANDLE{$id} // next;
Condition50%1/2
$LIVE_HANDLE{$id} // (next)
l!l
160
MC/DC0%0/1
$LIVE_HANDLE{$id} // (next)
$LIVE_HANDLE{$id}
Truth table50%1/2
A
A= $LIVE_HANDLE{$id}
Aresult
11
00
166 16 ▶ next if $object->{terminal};
Branch: 1 branch
BranchTrueFalseTotal
if $object->{"terminal"} 0 16 16
167 16 ▶ my $state = $OWNER_STATE{$id} // next;
Condition50%1/2
$OWNER_STATE{$id} // (next)
l!l
160
MC/DC0%0/1
$OWNER_STATE{$id} // (next)
$OWNER_STATE{$id}
Truth table50%1/2
A
A= $OWNER_STATE{$id}
Aresult
11
00
168 next if !$state->{loop}
169 16 ▶ || refaddr($state->{loop}) != refaddr($loop);
Branch: 1 branch
BranchTrueFalseTotal
if not $state->{"loop"} or builtin::refaddr($state->{"loop"}) != builtin::refaddr($loop) 0 16 16
Condition33%1/3
not $state->{"loop"} or builtin::refaddr($state->{"loop"}) != builtin::refaddr($loop)
l!l&&r!l&&!r
0016
MC/DC0%0/2
not $state->{"loop"} or builtin::refaddr($state->{"loop"}) != builtin::refaddr($loop)
not $state->{"loop"} builtin::refaddr($state->{"loop"}) != builtin::refaddr($loop)
Truth table33%1/3
not(A) or B
A= not $state->{"loop"}B= builtin::refaddr($state->{"loop"}) != builtin::refaddr($loop)
ABresult
1X1
011
000
170 16 push @object, $object;
171 }
172 18 return \@object;
173 }
174  
175 0 ▶sub CLONE ($class) {
Subroutine CLONE: not called CC=5 SCAR=34.0
176 0 for my $id (keys %LIVE_HANDLE) {
177 0 my $self = $LIVE_HANDLE{$id};
178 0 ▶ if (!$self) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self) 0 0 0
179 0 delete $LIVE_HANDLE{$id};
180 0 next;
181 }
182 0 ▶ next if $self->{terminal} || !defined $self->{fd};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"terminal"} or not defined $self->{"fd"} 0 0 0
Condition0%0/3
$self->{"terminal"} or not defined $self->{"fd"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"terminal"} or not defined $self->{"fd"}
$self->{"terminal"} not defined $self->{"fd"}
Truth table0%0/3
A or not(B)
A= $self->{"terminal"}B= not defined $self->{"fd"}
ABresult
1X1
011
000
183 0 $self->{fd} = _dup_fd($self->{fd});
184 0 $self->{handle_interpreter} = _interpreter_id();
185 0 $self->{cloned_signal_handle} = 1;
186 }
187 0 return;
188 }
189  
190 11 ▶sub DESTROY ($self) {
Subroutine DESTROY: called CC=12 SCAR=29.0
191 11 my $interpreter = eval { _interpreter_id() };
192 my $is_owner = !$self->{cloned_signal_handle}
193 && defined($interpreter)
194 && $self->{owner_pid} == $$
195 11 ▶ && $self->{owner_interpreter} == $interpreter;
Condition33%3/9
!$self->{'cloned_signal_handle'} && defined $interpreter && $self->{'owner_pid'} == $$ && $self->{'owner_interpreter'} == $interpreter
!ll&&!rl&&r
0011
not $self->{"cloned_signal_handle"} and defined $interpreter and $self->{"owner_pid"} == $$
!ll&&!rl&&r
0011
not $self->{"cloned_signal_handle"} and defined $interpreter
!ll&&!rl&&r
0011
MC/DC0%0/4
!$self->{'cloned_signal_handle'} && defined $interpreter && $self->{'owner_pid'} == $$ && $self->{'owner_interpreter'} == $interpreter
not $self->{"cloned_signal_handle"} defined $interpreter $self->{"owner_pid"} == $$ $self->{'owner_interpreter'} == $interpreter
Truth table20%1/5
not(A) and B and C && D
A= not $self->{"cloned_signal_handle"}B= defined $interpreterC= $self->{"owner_pid"} == $$D= $self->{'owner_interpreter'} == $interpreter
ABCDresult
0XXX0
10XX0
110X0
11100
11111
196 11 ▶ if ($is_owner) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_owner) 11 0 11
197 11 my $state = delete $OWNER_STATE{ $self->{id} };
198 11 ▶ eval { $state->{watcher}->cancel if $state && $state->{watcher}; 1 };
Branch: 1 branch
BranchTrueFalseTotal
if $state and $state->{"watcher"} 0 11 11
Condition33%1/3
$state and $state->{"watcher"}
!ll&&!rl&&r
1100
MC/DC0%0/2
$state and $state->{"watcher"}
$state $state->{"watcher"}
Truth table33%1/3
A and B
A= $stateB= $state->{"watcher"}
ABresult
0X0
100
111
199 }
200 11 my $live = $LIVE_HANDLE{ $self->{id} };
201 delete $LIVE_HANDLE{ $self->{id} }
202 11 ▶ if !$live || refaddr($live) == refaddr($self);
Branch: 1 branch
BranchTrueFalseTotal
if not $live or builtin::refaddr($live) == builtin::refaddr($self) 11 0 11
Condition66%2/3
not $live or builtin::refaddr($live) == builtin::refaddr($self)
l!l&&r!l&&!r
920
MC/DC0%0/2
not $live or builtin::refaddr($live) == builtin::refaddr($self)
not $live builtin::refaddr($live) == builtin::refaddr($self)
Truth table66%2/3
not(A) or B
A= not $liveB= builtin::refaddr($live) == builtin::refaddr($self)
ABresult
1X1
011
000
203 return if !defined($interpreter)
204 11 ▶ || $self->{handle_interpreter} != $interpreter;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $interpreter or $self->{"handle_interpreter"} != $interpreter 0 11 11
Condition33%1/3
not defined $interpreter or $self->{"handle_interpreter"} != $interpreter
l!l&&r!l&&!r
0011
MC/DC0%0/2
not defined $interpreter or $self->{"handle_interpreter"} != $interpreter
not defined $interpreter $self->{"handle_interpreter"} != $interpreter
Truth table33%1/3
not(A) or B
A= not defined $interpreterB= $self->{"handle_interpreter"} != $interpreter
ABresult
1X1
011
000
205 11 ▶ eval { _close_fd(delete $self->{fd}); 1 } if defined $self->{fd};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fd"} 2 9 11
206 11 return;
207 }
208  
209 package Linux::Event::Wakeup::_OwnerState;
210 7 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
211 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
212 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
213  
214 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
215  
216 package Linux::Event::Wakeup;
217  
218 7 1;
219  
220 __END__
« bench/run-callback-batching-fairness.pl ↑ Summary blib/lib/Linux/Event/Framer/Delimiter.pm »