blib/lib/KinoSearch1/Store/Lock.pm

filter: Statementstmt 79.3% 23 / 29 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.6% 7 / 11 Podpod 0.0% 0 / 5 totaltotal 67.3% 33 / 49 CC 3 SCAR 5.9
CC
3
Cov
79%
obtain
3.1
do_obtain
2.0
release
2.0
CRAP 1.8
« blib/lib/KinoSearch1/Search/Hit.pm ↑ Summary blib/lib/KinoSearch1/Index/TermVector.pm »
1 package KinoSearch1::Store::Lock;
2 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use KinoSearch1::Util::ToolSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use base qw( KinoSearch1::Util::Class );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 40 __PACKAGE__->init_instance_vars(
9 # constructor params / members
10 invindex => undef,
11 lock_name => undef,
12 timeout => 0,
13 );
14 }
15  
16 40 ▶use constant LOCK_POLL_INTERVAL => 1000;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # Attempt to aquire lock once per second until the timeout has been reached.
19 261 ▶sub obtain {
Subroutine obtain: called CC=3 SCAR=11.4
Pod undocumented
20 261 my $self = shift;
21  
22 # calculate maximum seconds to sleep
23 261 my $sleepcount = $self->{timeout} / LOCK_POLL_INTERVAL;
24  
25 # keep trying to obtain lock until timeout is reached
26 261 my $locked = $self->do_obtain;
27 261 ▶ while ( !$locked ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($locked) 2 259 261
28 2 ▶ croak("Couldn't get lock using '$self->{lock_name}'")
Branch: 1 branch
BranchTrueFalseTotal
if $sleepcount-- <= 0 2 0 2
29 if $sleepcount-- <= 0;
30 0 sleep 1;
31 0 $locked = $self->do_obtain;
32 }
33  
34 259 return $locked;
35 }
36  
37 =begin comment
38  
39 my $locked = $lock->do_obtain;
40  
41 Do the actual work to aquire the lock and return a boolean reflecting
42 success/failure.
43  
44 =end comment
45 =cut
46  
47 0 ▶sub do_obtain { shift->abstract_death }
Subroutine do_obtain: not called CC=1 SCAR=6.9
Pod undocumented
48  
49 =begin comment
50  
51 $lock->release;
52  
53 Release the lock.
54  
55 =end comment
56 =cut
57  
58 0 ▶sub release { shift->abstract_death }
Subroutine release: not called CC=1 SCAR=6.9
Pod undocumented
59  
60 =begin comment
61  
62 my $locked_or_not = $lock->is_locked;
63  
64 Return true if the resource is locked, false otherwise.
65  
66 =end comment
67 =cut
68  
69 0 ▶sub is_locked { shift->abstract_death }
Subroutine is_locked: not called CC=1 SCAR=6.9
Pod undocumented
70  
71 # Getter for lock_name.
72 0 ▶sub get_lock_name { shift->{lock_name} }
Subroutine get_lock_name: not called CC=1 SCAR=6.9
Pod undocumented
73  
74 40 1;
75  
76 __END__
« blib/lib/KinoSearch1/Search/Hit.pm ↑ Summary blib/lib/KinoSearch1/Index/TermVector.pm »