line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Concurrent; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1032
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
5
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
71
|
|
6
|
1
|
|
|
1
|
|
795
|
use POSIX qw(:errno_h); |
|
1
|
|
|
|
|
6705
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.05'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub DEBUG () {0} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
####################################################### |
12
|
|
|
|
|
|
|
sub TIEHASH |
13
|
|
|
|
|
|
|
{ |
14
|
0
|
|
|
0
|
|
|
my($package, $self)=@_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
0
|
|
|
|
unless($self->{READER} and $self->{WRITER}) { |
17
|
0
|
|
|
|
|
|
croak __PACKAGE__, "::TIEHASH needs READER and WRITER params"; |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
|
|
|
my $p; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
foreach my $type (qw(READER WRITER)) { |
22
|
0
|
|
|
|
|
|
($self->{$type.'_MODULE'}, @{$self->{$type}})=@{$self->{$type}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
} |
24
|
0
|
|
|
|
|
|
return bless $self, $package; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
####################################################### |
28
|
|
|
|
|
|
|
sub _tie |
29
|
|
|
|
|
|
|
{ |
30
|
0
|
|
|
0
|
|
|
my($self, $type)=@_; |
31
|
0
|
|
|
|
|
|
my $data; |
32
|
0
|
|
|
|
|
|
my $tries=10; |
33
|
0
|
|
0
|
|
|
|
do { |
34
|
0
|
|
|
|
|
|
$data=eval {$self->{$type."_MODULE"}->TIEHASH(@{$self->{$type}})}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if(not $data) { |
36
|
0
|
0
|
|
|
|
|
if($! != EAGAIN) { |
37
|
0
|
|
|
|
|
|
warn qq($self->{$type."_MODULE"}->TIEHASH(@{$self->{$type}}) failed: $!\n$@); |
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
warn "$$: $tries attemps"; |
41
|
0
|
|
|
|
|
|
$tries--; |
42
|
0
|
|
|
|
|
|
sleep 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} while(not $data and $tries > 0); |
45
|
0
|
|
|
|
|
|
return $data; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
####################################################### |
49
|
|
|
|
|
|
|
sub FETCH |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
0
|
|
|
my $self=shift; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $data=$self->_tie('READER'); |
54
|
0
|
0
|
|
|
|
|
croak "$$: Unable to tie data: $! ($@)" unless $data; |
55
|
0
|
|
|
|
|
|
return $data->FETCH(@_); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
####################################################### |
59
|
|
|
|
|
|
|
sub EXISTS |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
|
|
my $self=shift; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $data=$self->_tie('READER'); |
64
|
0
|
0
|
|
|
|
|
croak "$$: Unable to tie data: $! ($@)" unless $data; |
65
|
0
|
|
|
|
|
|
return $data->EXISTS(@_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
####################################################### |
73
|
|
|
|
|
|
|
sub STORE |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
0
|
|
|
my $self=shift; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
DEBUG and warn "Storing ", join ', ', @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $data=$self->_tie('WRITER'); |
80
|
0
|
0
|
|
|
|
|
croak "$$: Unable to tie data: $! ($@)" unless $data; |
81
|
0
|
|
|
|
|
|
return $data->STORE(@_); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
####################################################### |
85
|
|
|
|
|
|
|
sub CLEAR |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
0
|
|
|
my $self=shift; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $data=$self->_tie('WRITER'); |
90
|
0
|
0
|
|
|
|
|
croak "$$: Unable to tie data: $! ($@)" unless $data; |
91
|
0
|
|
|
|
|
|
return $data->CLEAR(@_); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
####################################################### |
95
|
|
|
|
|
|
|
sub DELETE |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
0
|
|
|
my $self=shift; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $data=$self->_tie('WRITER'); |
100
|
0
|
0
|
|
|
|
|
croak "$$: Unable to tie data: $! ($@)" unless $data; |
101
|
0
|
|
|
|
|
|
my $rv=$data->FETCH(@_); # work around a bug in MLDBM |
102
|
0
|
|
|
|
|
|
$data->DELETE(@_); |
103
|
0
|
|
|
|
|
|
return $rv; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
####################################################### |
107
|
|
|
|
|
|
|
sub FIRSTKEY |
108
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
0
|
|
|
my($self)=shift; |
110
|
0
|
|
|
|
|
|
my $data=$self->_tie('READER'); |
111
|
0
|
0
|
|
|
|
|
croak "$$: Unable to tie data: $! ($@)" unless $data; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$self->{_keys}=[]; |
114
|
0
|
|
|
|
|
|
my $q=$data->FIRSTKEY; |
115
|
0
|
|
|
|
|
|
DEBUG and warn "first key=$q"; |
116
|
0
|
|
|
|
|
|
while(defined $q) { |
117
|
0
|
|
|
|
|
|
push @{$self->{_keys}}, $q; |
|
0
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$q=$data->NEXTKEY($q); |
119
|
0
|
0
|
|
|
|
|
DEBUG and warn "next key=$q" if defined $q; |
120
|
|
|
|
|
|
|
} |
121
|
0
|
|
|
|
|
|
return $self->NEXTKEY; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
####################################################### |
125
|
|
|
|
|
|
|
sub NEXTKEY |
126
|
|
|
|
|
|
|
{ |
127
|
0
|
|
|
0
|
|
|
my($self)=shift; |
128
|
0
|
0
|
|
|
|
|
return unless $self->{_keys}; |
129
|
0
|
|
|
|
|
|
my $rv=shift @{$self->{_keys}}; |
|
0
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
delete $self->{_keys} if 0==@{$self->{_keys}}; |
|
0
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return $rv; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
__END__ |