line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IPC::ConcurrencyLimit::Lock::NFS; |
2
|
2
|
|
|
2
|
|
28290
|
use 5.008001; |
|
2
|
|
|
|
|
35
|
|
|
2
|
|
|
|
|
63
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
74
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
93
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
10
|
use Carp qw(croak); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
116
|
|
9
|
2
|
|
|
2
|
|
9
|
use File::Path qw(); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
30
|
|
10
|
2
|
|
|
2
|
|
10
|
use File::Spec; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
62
|
|
11
|
2
|
|
|
2
|
|
10
|
use Fcntl qw(:DEFAULT :flock); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1112
|
|
12
|
2
|
|
|
2
|
|
1549
|
use File::SharedNFSLock; |
|
2
|
|
|
|
|
15744
|
|
|
2
|
|
|
|
|
71
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1779
|
use IPC::ConcurrencyLimit::Lock; |
|
2
|
|
|
|
|
317
|
|
|
2
|
|
|
|
|
781
|
|
15
|
|
|
|
|
|
|
our @ISA = qw(IPC::ConcurrencyLimit::Lock); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
31
|
|
|
31
|
1
|
73139
|
my $class = shift; |
19
|
31
|
|
|
|
|
49
|
my $opt = shift; |
20
|
|
|
|
|
|
|
|
21
|
31
|
50
|
|
|
|
107
|
my $max_procs = $opt->{max_procs} |
22
|
|
|
|
|
|
|
or croak("Need a 'max_procs' parameter"); |
23
|
31
|
50
|
|
|
|
96
|
my $path = $opt->{path} |
24
|
|
|
|
|
|
|
or croak("Need a 'path' parameter"); |
25
|
|
|
|
|
|
|
|
26
|
31
|
|
|
|
|
73
|
my $h = {}; |
27
|
31
|
|
|
|
|
420
|
my $self = bless { |
28
|
|
|
|
|
|
|
max_procs => $max_procs, |
29
|
|
|
|
|
|
|
path => $path, |
30
|
|
|
|
|
|
|
the_lock => undef, |
31
|
|
|
|
|
|
|
lock_file => undef, |
32
|
|
|
|
|
|
|
id => undef, |
33
|
|
|
|
|
|
|
unique => "$h", |
34
|
|
|
|
|
|
|
unique_s => $h, |
35
|
|
|
|
|
|
|
} => $class; |
36
|
31
|
|
|
|
|
246
|
$self->{unique} =~ s/[^A-Za-z0-9.-_]+//g; |
37
|
31
|
|
|
|
|
115
|
$self->{unique} =~ s/HASH//; |
38
|
|
|
|
|
|
|
|
39
|
31
|
100
|
|
|
|
179
|
$self->_get_lock() or return undef; |
40
|
|
|
|
|
|
|
|
41
|
27
|
|
|
|
|
281
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _get_lock { |
45
|
31
|
|
|
31
|
|
48
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
31
|
|
|
|
|
1927
|
File::Path::mkpath($self->{path}); |
48
|
|
|
|
|
|
|
|
49
|
31
|
|
|
|
|
97
|
for my $worker (1 .. $self->{max_procs}) { |
50
|
244
|
|
|
|
|
189188
|
my $lock_file = File::Spec->catfile($self->{path}, $worker); |
51
|
|
|
|
|
|
|
|
52
|
244
|
|
|
|
|
1586
|
my $lock = File::SharedNFSLock->new( |
53
|
|
|
|
|
|
|
file => $lock_file, |
54
|
|
|
|
|
|
|
timeout_acquire => 0, |
55
|
|
|
|
|
|
|
timeout_stale => 0, |
56
|
|
|
|
|
|
|
unique_token => $self->{unique}, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
244
|
100
|
|
|
|
7206
|
if ($lock->lock()) { |
60
|
27
|
|
|
|
|
11292
|
$self->{the_lock} = $lock; |
61
|
27
|
|
|
|
|
77
|
$self->{id} = $worker; |
62
|
27
|
|
|
|
|
53
|
$self->{lock_file} = $lock_file; |
63
|
27
|
|
|
|
|
75
|
last; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
31
|
100
|
|
|
|
2079
|
return undef if not $self->{id}; |
68
|
27
|
|
|
|
|
82
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
0
|
1
|
|
sub lock_file { $_[0]->{lock_file} } |
72
|
0
|
|
|
0
|
1
|
|
sub path { $_[0]->{path} } |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Normally needs implementing to release the lock, |
75
|
|
|
|
|
|
|
# but in this case, we just hold on to the file handle that's flocked. |
76
|
|
|
|
|
|
|
# Thus, it will be released as soon as this object is freed. |
77
|
|
|
|
|
|
|
#sub DESTROY {} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |