]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Lock.pm
sharedkv: fork()-friendly key-value store
[public-inbox.git] / lib / PublicInbox / Lock.pm
index b2c8227f0a66c8940d9be8e60afb8571015f0fc0..7fd1774584c3df93b80ebad3f2e6f5ad4bdc8229 100644 (file)
@@ -4,9 +4,10 @@
 # Base class for per-inbox locking
 package PublicInbox::Lock;
 use strict;
-use warnings;
+use v5.10.1;
 use Fcntl qw(:flock :DEFAULT);
 use Carp qw(croak);
+use PublicInbox::OnDestroy;
 
 # we only acquire the flock if creating or reindexing;
 # PublicInbox::Import already has the lock on its own.
@@ -32,4 +33,11 @@ sub lock_release {
        close $lockfh or croak "close $lock_path failed: $!\n";
 }
 
+# caller must use return value
+sub lock_for_scope {
+       my ($self) = @_;
+       $self->lock_acquire;
+       PublicInbox::OnDestroy->new(\&lock_release, $self);
+}
+
 1;