| 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
Condition33%1/3
$self->[0] and $self->[2] == $$
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] == $$
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$timeout // -1
$timeout
Truth table50%1/2
A
A= $timeout
| |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | return unless defined $idx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 1 | my $guard = bless [$self, $idx, $$], 'Data::Pool::Shared::Guard'; | |||||||||||||||||||||||||||
| 35 | 1 | ▶ | return wantarray ? ($idx, $guard) : $guard; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | 4 | my $guard = bless [$self, $idx, $$], 'Data::Pool::Shared::Guard'; | |||||||||||||||||||||||||||
| 43 | 4 | ▶ | return wantarray ? ($idx, $guard) : $guard; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||