line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2023 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.03. |
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
|
|
1567
|
use vars '$VERSION'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
114
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.010'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
12
|
use base 'Mail::Box::Locker'; |
|
2
|
|
|
|
|
58
|
|
|
2
|
|
|
|
|
540
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
71
|
|
16
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
46
|
|
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1268
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init($) |
22
|
1
|
|
|
1
|
0
|
14
|
{ my ($self, $args) = @_; |
23
|
1
|
|
|
|
|
8
|
$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
|
|
|
|
17
|
{ 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
|
|
|
|
|
15
|
|
42
|
|
|
|
|
|
|
( %$args |
43
|
|
|
|
|
|
|
, method => $method |
44
|
|
|
|
|
|
|
, timeout => 1 |
45
|
|
|
|
|
|
|
) |
46
|
|
|
|
|
|
|
}; |
47
|
3
|
100
|
|
|
|
202
|
next unless defined $locker; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
4
|
push @lockers, $locker; |
50
|
2
|
|
|
|
|
6
|
push @used, $method; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
5
|
$self->{MBLM_lockers} = \@lockers; |
54
|
1
|
|
|
|
|
13
|
$self->log(PROGRESS => "Multi-locking via @used."); |
55
|
1
|
|
|
|
|
28
|
$self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#------------------------------------------- |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub name() {'MULTI'} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _try_lock($) |
63
|
1
|
|
|
1
|
|
2
|
{ my $self = shift; |
64
|
1
|
|
|
|
|
3
|
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
|
2
|
{ my $self = shift; |
80
|
1
|
50
|
|
|
|
4
|
$self->hasLock |
81
|
|
|
|
|
|
|
or return $self; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
3
|
$_->unlock foreach $self->lockers; |
84
|
1
|
|
|
|
|
5
|
$self->SUPER::unlock; |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
2
|
$self; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub lock() |
90
|
2
|
|
|
2
|
1
|
1279
|
{ my $self = shift; |
91
|
2
|
100
|
|
|
|
10
|
return 1 if $self->hasLock; |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
6
|
my $timeout = $self->timeout; |
94
|
1
|
50
|
|
|
|
6
|
my $end = $timeout eq 'NOTIMEOUT' ? -1 : $timeout; |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
4
|
while(1) |
97
|
1
|
50
|
|
|
|
4
|
{ 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
|
4
|
sub lockers() { @{shift->{MBLM_lockers}} } |
|
2
|
|
|
|
|
17
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |