| 1 | package Ubic::SingletonLock; | ||||||||||
| 2 | 154 | $Ubic::SingletonLock::VERSION = '1.59'; | |||||||||
| 3 | 154 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 154 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: lock which can be safely created several times from the same process without deadlocking | ||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 154 | ▶ | use Params::Validate; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 154 | ▶ | use Scalar::Util qw(weaken); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 154 | ▶ | use Ubic::Lockf; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 154 | our %LOCKS; | |||||||||
| 15 | |||||||||||
| 16 | sub new { | ||||||||||
| 17 | 336 | ▶ | my ($class, $file, $options) = validate_pos(@_, 1, 1, 0); | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 18 | |||||||||||
| 19 | 336 | ▶ | if ($LOCKS{$file}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 99 | return $LOCKS{$file}; | |||||||||
| 21 | } | ||||||||||
| 22 | 237 | my $lock = lockf($file, $options); | |||||||||
| 23 | 237 | my $self = bless { file => $file, lock => $lock } => $class; | |||||||||
| 24 | |||||||||||
| 25 | 237 | $LOCKS{$file} = $self; | |||||||||
| 26 | 237 | weaken $LOCKS{$file}; | |||||||||
| 27 | 237 | return $self; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | sub DESTROY { | ||||||||||
| 31 | 224 | ▶ | my $self = shift; | ||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 224 | local $@; | |||||||||
| 33 | 224 | delete $LOCKS{ $self->{file} }; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | 154 | 1; | |||||||||
| 38 | |||||||||||
| 39 | __END__ | ||||||||||