diff options
author | Eric Wong <e@80x24.org> | 2020-12-31 13:51:23 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-01 05:00:38 +0000 |
commit | fa7bab31c9e5ded5c832b42de56f48dbdf9de972 (patch) | |
tree | 119da483ffc9a877bfa9e703f3eca9c8da4b93b8 /lib/PublicInbox/Lock.pm | |
parent | 80e70e03c788b5ed776e508e6f7bc3557819c19d (diff) | |
download | public-inbox-fa7bab31c9e5ded5c832b42de56f48dbdf9de972.tar.gz |
This is intended for maintaining Maildir states, mbox message deduplication, but may be useful for other purposes...
Diffstat (limited to 'lib/PublicInbox/Lock.pm')
-rw-r--r-- | lib/PublicInbox/Lock.pm | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/PublicInbox/Lock.pm b/lib/PublicInbox/Lock.pm index b2c8227f..7fd17745 100644 --- a/lib/PublicInbox/Lock.pm +++ b/lib/PublicInbox/Lock.pm @@ -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; |