line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2020 by [Mark Overmeer]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
|
|
|
|
|
|
# This code is part of distribution Mail-Box. Meta-POD processed with |
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Mail::Box::Locker::Multi; |
10
|
2
|
|
|
2
|
|
1636
|
use vars '$VERSION'; |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
133
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.009'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
13
|
use base 'Mail::Box::Locker'; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
597
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
16
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1312
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init($) |
22
|
1
|
|
|
1
|
0
|
15
|
{ my ($self, $args) = @_; |
23
|
1
|
|
|
|
|
7
|
$self->SUPER::init($args); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my @use |
26
|
1
|
50
|
|
|
|
8
|
= exists $args->{use} ? @{delete $args->{use}} |
|
0
|
50
|
|
|
|
0
|
|
27
|
|
|
|
|
|
|
: $^O eq 'MSWin32' ? qw/Flock/ |
28
|
|
|
|
|
|
|
: qw/NFS FcntlLock Flock/; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
3
|
my (@lockers, @used); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
3
|
foreach my $method (@use) |
33
|
3
|
50
|
|
|
|
15
|
{ if(UNIVERSAL::isa($method, 'Mail::Box::Locker')) |
34
|
0
|
|
|
|
|
0
|
{ push @lockers, $method; |
35
|
0
|
|
|
|
|
0
|
(my $used = ref $method) =~ s/.*\:\://; |
36
|
0
|
|
|
|
|
0
|
push @used, $used; |
37
|
0
|
|
|
|
|
0
|
next; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $locker = eval |
41
|
3
|
|
|
|
|
6
|
{ Mail::Box::Locker->new |
|
3
|
|
|
|
|
17
|
|
42
|
|
|
|
|
|
|
( %$args |
43
|
|
|
|
|
|
|
, method => $method |
44
|
|
|
|
|
|
|
, timeout => 1 |
45
|
|
|
|
|
|
|
) |
46
|
|
|
|
|
|
|
}; |
47
|
3
|
100
|
|
|
|
300
|
next unless defined $locker; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
5
|
push @lockers, $locker; |
50
|
2
|
|
|
|
|
6
|
push @used, $method; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
5
|
$self->{MBLM_lockers} = \@lockers; |
54
|
1
|
|
|
|
|
11
|
$self->log(PROGRESS => "Multi-locking via @used."); |
55
|
1
|
|
|
|
|
30
|
$self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#------------------------------------------- |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub name() {'MULTI'} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _try_lock($) |
63
|
1
|
|
|
1
|
|
2
|
{ my $self = shift; |
64
|
1
|
|
|
|
|
2
|
my @successes; |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
4
|
foreach my $locker ($self->lockers) |
67
|
|
|
|
|
|
|
{ |
68
|
2
|
50
|
|
|
|
7
|
unless($locker->lock) |
69
|
0
|
|
|
|
|
0
|
{ $_->unlock foreach @successes; |
70
|
0
|
|
|
|
|
0
|
return 0; |
71
|
|
|
|
|
|
|
} |
72
|
2
|
|
|
|
|
7
|
push @successes, $locker; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
7
|
1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub unlock() |
79
|
1
|
|
|
1
|
1
|
4
|
{ my $self = shift; |
80
|
1
|
50
|
|
|
|
2
|
$self->hasLock |
81
|
|
|
|
|
|
|
or return $self; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
6
|
$_->unlock foreach $self->lockers; |
84
|
1
|
|
|
|
|
15
|
$self->SUPER::unlock; |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
3
|
$self; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub lock() |
90
|
2
|
|
|
2
|
1
|
917
|
{ my $self = shift; |
91
|
2
|
100
|
|
|
|
10
|
return 1 if $self->hasLock; |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
6
|
my $timeout = $self->timeout; |
94
|
1
|
50
|
|
|
|
7
|
my $end = $timeout eq 'NOTIMEOUT' ? -1 : $timeout; |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
2
|
while(1) |
97
|
1
|
50
|
|
|
|
3
|
{ return $self->SUPER::lock |
98
|
|
|
|
|
|
|
if $self->_try_lock; |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
0
|
last unless --$end; |
101
|
0
|
|
|
|
|
0
|
sleep 1; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
return 0; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub isLocked() |
108
|
0
|
|
|
0
|
1
|
0
|
{ my $self = shift; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Try get a lock |
111
|
0
|
0
|
|
|
|
0
|
$self->_try_lock($self->filename) or return 0; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# and release it immediately |
114
|
0
|
|
|
|
|
0
|
$self->unlock; |
115
|
0
|
|
|
|
|
0
|
1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
#------------------------------------------- |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
2
|
1
|
3
|
sub lockers() { @{shift->{MBLM_lockers}} } |
|
2
|
|
|
|
|
10
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |