| 1 | package Data::Sync::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::Sync::Shared', $VERSION); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # ithreads: blessed shared-memory handles must never be cloned into a | ||||||||||||||||||||||||||||
| 10 | # child thread -- the clone would double-free the handle on thread exit. | ||||||||||||||||||||||||||||
| 11 | 0 | ▶ | { no strict 'refs'; *{"${_}::CLONE_SKIP"} = sub { 1 } for qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | Data::Sync::Shared::Semaphore | ||||||||||||||||||||||||||||
| 13 | Data::Sync::Shared::Barrier | ||||||||||||||||||||||||||||
| 14 | Data::Sync::Shared::RWLock | ||||||||||||||||||||||||||||
| 15 | Data::Sync::Shared::Condvar | ||||||||||||||||||||||||||||
| 16 | Data::Sync::Shared::Once | ||||||||||||||||||||||||||||
| 17 | Data::Sync::Shared::RWLock::Guard | ||||||||||||||||||||||||||||
| 18 | Data::Sync::Shared::Condvar::Guard | ||||||||||||||||||||||||||||
| 19 | Data::Sync::Shared::Semaphore::Guard | ||||||||||||||||||||||||||||
| 20 | ); } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # Guard objects -- auto-release on scope exit | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 13 | package Data::Sync::Shared::RWLock::Guard { | |||||||||||||||||||||||||||
| 25 | 13 | our $VERSION = '0.11'; # indexable package: PAUSE needs a version here too | |||||||||||||||||||||||||||
| 26 | 2 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||
| 27 | # Only the process that took the lock may release it: after fork the | ||||||||||||||||||||||||||||
| 28 | # child inherits the guard object, and its global destruction would | ||||||||||||||||||||||||||||
| 29 | # otherwise release a lock the PARENT still holds -- breaking mutual | ||||||||||||||||||||||||||||
| 30 | # exclusion for every other process. | ||||||||||||||||||||||||||||
| 31 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | 2 | ▶ | $self->[0]->${\$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] == $$
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub Data::Sync::Shared::RWLock::rdlock_guard { | ||||||||||||||||||||||||||
|
Subroutine
rdlock_guard: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 1 | $self->rdlock(@_); | |||||||||||||||||||||||||||
| 39 | 1 | bless [$self, 'rdunlock', $$], 'Data::Sync::Shared::RWLock::Guard'; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | sub Data::Sync::Shared::RWLock::wrlock_guard { | ||||||||||||||||||||||||||
|
Subroutine
wrlock_guard: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | 1 | $self->wrlock(@_); | |||||||||||||||||||||||||||
| 45 | 1 | bless [$self, 'wrunlock', $$], 'Data::Sync::Shared::RWLock::Guard'; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 13 | package Data::Sync::Shared::Condvar::Guard { | |||||||||||||||||||||||||||
| 49 | 13 | our $VERSION = '0.11'; # indexable package: PAUSE needs a version here too | |||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||
| 51 | # Only the process that took the mutex may release it -- see the note | ||||||||||||||||||||||||||||
| 52 | # on RWLock::Guard::DESTROY. | ||||||||||||||||||||||||||||
| 53 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 54 | 1 | ▶ | $self->[0]->unlock if $self->[0] && $self->[1] == $$; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->[0] and $self->[1] == $$
MC/DC0%0/2
$self->[0] and $self->[1] == $$
$self->[0]
$self->[1] == $$
Truth table33%1/3
A and B
A= $self->[0]B= $self->[1] == $$
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub Data::Sync::Shared::Condvar::lock_guard { | ||||||||||||||||||||||||||
|
Subroutine
lock_guard: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | 1 | $self->lock; | |||||||||||||||||||||||||||
| 61 | 1 | bless [$self, $$], 'Data::Sync::Shared::Condvar::Guard'; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # Condvar wait_while -- loop until predicate returns false | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 13 | my $condvar_clock; | |||||||||||||||||||||||||||
| 67 | 5 | ▶ | sub Data::Sync::Shared::Condvar::wait_while { | ||||||||||||||||||||||||||
|
Subroutine
wait_while: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 5 | my ($self, $pred, $timeout) = @_; | |||||||||||||||||||||||||||
| 69 | 5 | ▶ | $timeout //= -1; | ||||||||||||||||||||||||||
|
Condition50%1/2
$timeout //= -1
MC/DC0%0/1
$timeout //= -1
$timeout
Truth table50%1/2
A
A= $timeout
| |||||||||||||||||||||||||||||
| 70 | 5 | ▶ | return 1 unless $pred->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 4 | ▶ | return 0 if $timeout == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 3 | my $deadline; | |||||||||||||||||||||||||||
| 73 | 3 | ▶ | if ($timeout > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 3 | require Time::HiRes; | |||||||||||||||||||||||||||
| 75 | 3 | ▶ | $condvar_clock //= Time::HiRes::CLOCK_MONOTONIC(); | ||||||||||||||||||||||||||
|
Condition66%2/3
$condvar_clock //= Time::HiRes::CLOCK_MONOTONIC()
MC/DC0%0/2
$condvar_clock //= Time::HiRes::CLOCK_MONOTONIC()
$condvar_clock
Time::HiRes::CLOCK_MONOTONIC()
Truth table66%2/3
A //= B
A= $condvar_clockB= Time::HiRes::CLOCK_MONOTONIC()
| |||||||||||||||||||||||||||||
| 76 | 3 | $deadline = Time::HiRes::clock_gettime($condvar_clock) + $timeout; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 3 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 5 | ▶ | if (defined $deadline) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 5 | my $remaining = $deadline - Time::HiRes::clock_gettime($condvar_clock); | |||||||||||||||||||||||||||
| 81 | 5 | ▶ | return 0 if $remaining <= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 3 | $self->wait($remaining); | |||||||||||||||||||||||||||
| 83 | # Fall through to re-check predicate even on timeout -- the | ||||||||||||||||||||||||||||
| 84 | # condition may have cleared just before our deadline expired. | ||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | 0 | $self->wait; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } while ($pred->()); | ||||||||||||||||||||||||||||
| 89 | 1 | return 1; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # Semaphore guard | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 3 | ▶ | sub Data::Sync::Shared::Semaphore::acquire_guard { | ||||||||||||||||||||||||||
|
Subroutine
acquire_guard: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 3 | my ($self, $n, $timeout) = @_; | |||||||||||||||||||||||||||
| 96 | 3 | ▶ | $n //= 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$n //= 1
MC/DC100%1/1
$n //= 1
$n
Truth table100%2/2
A
A= $n
| |||||||||||||||||||||||||||||
| 97 | 3 | ▶ | if ($n == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 2 | ▶ | $self->acquire($timeout // -1) or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$timeout // -1
MC/DC100%1/1
$timeout // -1
$timeout
Truth table100%2/2
A
A= $timeout
| |||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||
| 100 | 1 | ▶ | $self->acquire_n($n, $timeout // -1) or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$timeout // -1
MC/DC0%0/1
$timeout // -1
$timeout
Truth table50%1/2
A
A= $timeout
| |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 2 | bless [$self, $n, $$], 'Data::Sync::Shared::Semaphore::Guard'; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 13 | package Data::Sync::Shared::Semaphore::Guard { | |||||||||||||||||||||||||||
| 106 | 13 | our $VERSION = '0.11'; # indexable package: PAUSE needs a version here too | |||||||||||||||||||||||||||
| 107 | 2 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||
| 108 | # Only the process that took the permits may release them: a forked | ||||||||||||||||||||||||||||
| 109 | # child's global destruction would otherwise release permits it never | ||||||||||||||||||||||||||||
| 110 | # acquired, pushing the semaphore count above what is actually free. | ||||||||||||||||||||||||||||
| 111 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 2 | ▶ | $self->[0]->release($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] == $$
| |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 13 | 1; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||