line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
;# $Id |
2
|
|
|
|
|
|
|
;# |
3
|
|
|
|
|
|
|
;# @COPYRIGHT@ |
4
|
|
|
|
|
|
|
;# |
5
|
|
|
|
|
|
|
;# $Log: Manager.pm,v $ |
6
|
|
|
|
|
|
|
;# Revision 0.2 1999/12/07 20:51:05 ram |
7
|
|
|
|
|
|
|
;# Baseline for 0.2 release. |
8
|
|
|
|
|
|
|
;# |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
16
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1136
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
######################################################################## |
13
|
|
|
|
|
|
|
package LockFile::Manager; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# A pool of all created locks. |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $MANAGER = undef; # The main manager |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# ->make |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
# Creates a new LockFile::Manager to hold the locks. |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# Attributes: |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# pool hash of LockFile::Lock objects |
29
|
|
|
|
|
|
|
# wfunc warning function to be called |
30
|
|
|
|
|
|
|
# efunc error function to be called |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
sub make { |
33
|
2
|
|
|
2
|
0
|
6
|
my $self = bless {}, shift; |
34
|
2
|
|
|
|
|
1236
|
my ($wfunc, $efunc) = @_; |
35
|
2
|
|
|
|
|
18
|
$self->{'pool'} = {}; |
36
|
2
|
|
|
|
|
6
|
$self->{'wfunc'} = $wfunc; |
37
|
2
|
|
|
|
|
6
|
$self->{'efunc'} = $efunc; |
38
|
2
|
|
|
|
|
24
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# |
42
|
|
|
|
|
|
|
# Attribute access |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
4
|
0
|
28
|
sub pool { $_[0]->{'pool'} } |
46
|
1
|
|
|
1
|
0
|
21
|
sub wfunc { $_[0]->{'wfunc'} } |
47
|
0
|
|
|
0
|
0
|
0
|
sub efunc { $_[0]->{'efunc'} } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# ->manager -- "once" function |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
# Returns the main manager. |
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
sub manager { |
55
|
2
|
|
|
2
|
0
|
6
|
my ($class, $wfunc, $efunc) = @_; |
56
|
2
|
|
33
|
|
|
16
|
return $MANAGER || ($MANAGER = $class->make($wfunc, $efunc)); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
# ->remember |
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
# Remember created locks. |
63
|
|
|
|
|
|
|
# |
64
|
|
|
|
|
|
|
sub remember { |
65
|
1
|
|
|
1
|
0
|
15
|
my $self = shift; |
66
|
1
|
|
|
|
|
2
|
my ($lock) = @_; # A LockFile::Lock object |
67
|
1
|
|
|
|
|
9
|
my $pool = $self->pool; |
68
|
1
|
50
|
|
|
|
90
|
if (exists $pool->{$lock}) { |
69
|
0
|
|
|
|
|
0
|
&{$self->efunc}("lock $lock already remembered"); |
|
0
|
|
|
|
|
0
|
|
70
|
0
|
|
|
|
|
0
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
1
|
|
|
|
|
15
|
$pool->{$lock} = $lock; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# |
76
|
|
|
|
|
|
|
# ->forget |
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
# Forget about a lock. |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
sub forget { |
81
|
1
|
|
|
1
|
0
|
19
|
my $self = shift; |
82
|
1
|
|
|
|
|
1
|
my ($lock) = @_; # A LockFile::Lock object |
83
|
1
|
|
|
|
|
3
|
my $pool = $self->pool; |
84
|
1
|
50
|
|
|
|
8
|
unless (exists $pool->{$lock}) { |
85
|
0
|
|
|
|
|
0
|
&{$self->efunc}("lock $lock not remembered yet"); |
|
0
|
|
|
|
|
0
|
|
86
|
0
|
|
|
|
|
0
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
1
|
|
|
|
|
6
|
delete $pool->{$lock}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
# ->release_all |
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
# Release all the locks. |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
sub release_all { |
97
|
2
|
|
|
2
|
0
|
95
|
my $self = shift; |
98
|
2
|
|
|
|
|
48
|
my $pool = $self->pool; |
99
|
2
|
|
|
|
|
35
|
my $locks = scalar keys %$pool; |
100
|
2
|
100
|
|
|
|
7
|
return unless $locks; |
101
|
|
|
|
|
|
|
|
102
|
1
|
50
|
|
|
|
12
|
my $s = $locks == 1 ? '' : 's'; |
103
|
1
|
|
|
|
|
68
|
&{$self->wfunc}("releasing $locks pending lock$s..."); |
|
1
|
|
|
|
|
12
|
|
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
|
|
174
|
foreach my $lock (values %$pool) { |
106
|
1
|
|
|
|
|
17
|
$lock->release; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub END { $MANAGER->release_all if defined $MANAGER } |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|