⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lock.pm

📁 外国人写的Perl搜索引擎程序
💻 PM
字号:
package KinoSearch::Store::Lock;use strict;use warnings;use KinoSearch::Util::ToolSet;use base qw( KinoSearch::Util::Class );BEGIN {    __PACKAGE__->init_instance_vars(        # constructor params / members        invindex  => undef,        lock_name => undef,        timeout   => 0,    );}use constant LOCK_POLL_INTERVAL => 1000;# Attempt to aquire lock once per second until the timeout has been reached.sub obtain {    my $self = shift;    # calculate maximum seconds to sleep    my $sleepcount = $self->{timeout} / LOCK_POLL_INTERVAL;    # keep trying to obtain lock until timeout is reached    my $locked = $self->do_obtain;    while ( !$locked ) {        croak("Couldn't get lock using '$self->{lock_name}'")            if $sleepcount-- <= 0;        sleep 1;        $locked = $self->do_obtain;    }    return $locked;}=begin comment    my $locked = $lock->do_obtain;Do the actual work to aquire the lock and return a boolean reflectingsuccess/failure.=end comment=cutsub do_obtain { shift->abstract_death }=begin comment    $lock->release;Release the lock.=end comment=cutsub release { shift->abstract_death }=begin comment    my $locked_or_not = $lock->is_locked;Return true if the resource is locked, false otherwise.=end comment=cutsub is_locked { shift->abstract_death }# Getter for lock_name.sub get_lock_name { shift->{lock_name} }1;__END__=begin devdocs=head1 NAMEKinoSearch::Store::Lock - mutex lock on an invindex=head1 SYNOPSIS    # abstract base class, but here's typical usage:        my $lock = $invindex->make_lock(        lock_name => COMMIT_LOCK_NAME,        timeout   => 5000,    );=head1 DESCRIPTIONThe Lock class produces an interprocess mutex lock.  It does not rely onflock.Lock must be subclassed, and instances must be constructed using theC<make_lock> factory method of KinoSearch::Store::InvIndex.=head1 COPYRIGHTCopyright 2005-2007 Marvin Humphrey=head1 LICENSE, DISCLAIMER, BUGS, etc.See L<KinoSearch|KinoSearch> version 0.163.=end devdocs=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -