line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IPC::ConcurrencyLimit; |
2
|
10
|
|
|
10
|
|
131695
|
use 5.008001; |
|
10
|
|
|
|
|
28
|
|
3
|
10
|
|
|
10
|
|
41
|
use strict; |
|
10
|
|
|
|
|
43
|
|
|
10
|
|
|
|
|
258
|
|
4
|
10
|
|
|
10
|
|
40
|
use warnings; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
501
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.17'; |
7
|
|
|
|
|
|
|
|
8
|
10
|
|
|
10
|
|
49
|
use Carp qw(croak); |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
5130
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
81
|
|
|
81
|
1
|
5483
|
my $class = shift; |
12
|
81
|
|
|
|
|
301
|
my %params = @_; |
13
|
81
|
|
|
|
|
127
|
my $type = delete $params{type}; |
14
|
81
|
100
|
|
|
|
215
|
$type = 'Flock' if not defined $type; |
15
|
|
|
|
|
|
|
|
16
|
81
|
|
|
|
|
287
|
my $lock_class = $class . "::Lock::$type"; |
17
|
81
|
50
|
|
|
|
6750
|
if (not eval "require $lock_class; 1;") { |
18
|
0
|
|
0
|
|
|
0
|
my $err = $@ || 'Zombie error'; |
19
|
0
|
|
|
|
|
0
|
croak("Invalid lock type '$type'. Could not load lock class '$lock_class': $err"); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
81
|
|
|
|
|
814
|
my $self = bless { |
23
|
|
|
|
|
|
|
opt => { |
24
|
|
|
|
|
|
|
max_procs => 1, |
25
|
|
|
|
|
|
|
%params, |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
lock_class => $lock_class, |
28
|
|
|
|
|
|
|
lock_obj => undef, |
29
|
|
|
|
|
|
|
} => $class; |
30
|
|
|
|
|
|
|
|
31
|
81
|
|
|
|
|
400
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub get_lock { |
35
|
454
|
|
|
454
|
1
|
7768
|
my $self = shift; |
36
|
454
|
100
|
|
|
|
1818
|
return $self->{lock_obj}->id() if $self->{lock_obj}; |
37
|
|
|
|
|
|
|
|
38
|
449
|
|
|
|
|
928
|
my $class = $self->{lock_class}; |
39
|
449
|
|
|
|
|
4863
|
$self->{lock_obj} = $class->new($self->{opt}); |
40
|
|
|
|
|
|
|
|
41
|
449
|
100
|
|
|
|
2434
|
return $self->{lock_obj} ? $self->{lock_obj}->id() : undef; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub is_locked { |
45
|
2
|
|
|
2
|
1
|
479
|
my $self = shift; |
46
|
2
|
100
|
|
|
|
9
|
return $self->{lock_obj} ? 1 : 0; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub release_lock { |
50
|
48
|
|
|
48
|
1
|
851
|
my $self = shift; |
51
|
48
|
100
|
|
|
|
653
|
return undef if not $self->{lock_obj}; |
52
|
47
|
|
|
|
|
112
|
$self->{lock_obj} = undef; |
53
|
47
|
|
|
|
|
252
|
return 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub lock_id { |
57
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
58
|
2
|
100
|
|
|
|
9
|
return undef if not $self->{lock_obj}; |
59
|
1
|
|
|
|
|
3
|
return $self->{lock_obj}->id; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub heartbeat { |
63
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
my $lock = $self->{lock_obj}; |
65
|
0
|
0
|
|
|
|
|
return if not $lock; |
66
|
0
|
0
|
|
|
|
|
if (not $lock->heartbeat) { |
67
|
0
|
|
|
|
|
|
$self->release_lock; |
68
|
0
|
|
|
|
|
|
return(); |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
return 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |