blib/lib/Data/Pool/Shared.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 70.0% 7 / 10 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 3 totaltotal 77.0% 47 / 61 CC 9 SCAR 10.9
CC
9
Cov
85%
alloc_guard
4.3
DESTROY
3.5
try_alloc_guard
3.0
CRAP 3.0
↑ Summary Shared.xs »
1 package Data::Pool::Shared;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 our $VERSION = '0.11';
5  
6 13 require XSLoader;
7 13 XSLoader::load('Data::Pool::Shared', $VERSION);
8  
9 0 ▶sub CLONE_SKIP { 1 } # blessed C-pointer handle: never clone into ithreads (double-free)
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
10  
11 # Variant @ISA -- inherit alloc/free/is_allocated/capacity/etc. from base
12  
13 13 @Data::Pool::Shared::I64::ISA = ('Data::Pool::Shared');
14 13 @Data::Pool::Shared::F64::ISA = ('Data::Pool::Shared');
15 13 @Data::Pool::Shared::I32::ISA = ('Data::Pool::Shared');
16 13 @Data::Pool::Shared::Str::ISA = ('Data::Pool::Shared');
17  
18 # Guard -- auto-free on scope exit
19  
20 13 package Data::Pool::Shared::Guard {
21 13 our $VERSION = '0.11'; # indexable package: PAUSE needs a version here too
22 5 ▶ sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=12.5
23 5 my $self = shift;
24 # only the creating process frees the slot: after fork the child inherits
25 # the guard object and must not free the parent's still-owned slot.
26 5 ▶ eval { $self->[0]->free($self->[1]) } if $self->[0] && $self->[2] == $$;
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0] and $self->[2] == $$ 5 0 5
Condition33%1/3
$self->[0] and $self->[2] == $$
!ll&&!rl&&r
005
MC/DC0%0/2
$self->[0] and $self->[2] == $$
$self->[0] $self->[2] == $$
Truth table33%1/3
A and B
A= $self->[0]B= $self->[2] == $$
ABresult
0X0
100
111
27 }
28 }
29  
30 1 ▶sub alloc_guard {
Subroutine alloc_guard: called CC=4 SCAR=14.6
Pod undocumented
31 1 my ($self, $timeout) = @_;
32 1 ▶ my $idx = $self->alloc($timeout // -1);
Condition50%1/2
$timeout // -1
l!l
01
MC/DC0%0/1
$timeout // -1
$timeout
Truth table50%1/2
A
A= $timeout
Aresult
11
00
33 1 ▶ return unless defined $idx;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $idx 0 1 1
34 1 my $guard = bless [$self, $idx, $$], 'Data::Pool::Shared::Guard';
35 1 ▶ return wantarray ? ($idx, $guard) : $guard;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
36 }
37  
38 5 ▶sub try_alloc_guard {
Subroutine try_alloc_guard: called CC=3 SCAR=11.0
Pod undocumented
39 5 my ($self) = @_;
40 5 my $idx = $self->try_alloc;
41 5 ▶ return unless defined $idx;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $idx 1 4 5
42 4 my $guard = bless [$self, $idx, $$], 'Data::Pool::Shared::Guard';
43 4 ▶ return wantarray ? ($idx, $guard) : $guard;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 2 4
44 }
45  
46 # Iterate allocated slots
47  
48 2 ▶sub each_allocated {
Subroutine each_allocated: called CC=2 SCAR=6.9
Pod undocumented
49 2 my ($self, $cb) = @_;
50 2 $cb->($_) for @{ $self->allocated_slots };
51 }
52  
53 13 1;
54  
55 __END__
↑ Summary Shared.xs »