xapian-core  1.4.22
Public Types | Public Member Functions | Private Attributes | List of all members
FlintLock Class Reference

#include <flint_lock.h>

+ Collaboration diagram for FlintLock:

Public Types

enum  reason {

Public Member Functions

 FlintLock (const std::string &filename_)
 Standard constructor. More...
 FlintLock ()
 Constructor for use in read-only cases (like single-file glass). More...
 operator bool () const
 ~FlintLock ()
bool test () const
 Test if the lock is held. More...
reason lock (bool exclusive, bool wait, std::string &explanation)
 Attempt to obtain the lock. More...
void release ()
 Release the lock. More...
void throw_databaselockerror (FlintLock::reason why, const std::string &db_dir, const std::string &explanation) const
 Throw Xapian::DatabaseLockError. More...

Private Attributes

std::string filename
int fd = -1
pid_t pid

Detailed Description

Definition at line 39 of file flint_lock.h.

Member Enumeration Documentation

◆ reason


Definition at line 51 of file flint_lock.h.

Constructor & Destructor Documentation

◆ FlintLock() [1/2]

FlintLock::FlintLock ( const std::string &  filename_)

Standard constructor.

Definition at line 60 of file flint_lock.h.

◆ FlintLock() [2/2]

FlintLock::FlintLock ( )

Constructor for use in read-only cases (like single-file glass).

Definition at line 69 of file flint_lock.h.

◆ ~FlintLock()

FlintLock::~FlintLock ( )

Definition at line 80 of file flint_lock.h.

References lock(), release(), test(), and throw_databaselockerror().

Member Function Documentation

◆ lock()

FlintLock::reason FlintLock::lock ( bool  exclusive,
bool  wait,
std::string &  explanation 

Attempt to obtain the lock.

If the attempt fails with code "UNKNOWN", the string supplied in the explanation parameter will be set to contain any details available of the reason for the failure.

exclusiveGet an exclusive lock? Value currently ignored, and the lock is always exclusive.
waitWait until we can get the lock?

Definition at line 125 of file flint_lock.cc.

References Assert, close(), Xapian::Internal::closefrom(), errno_to_string(), O_CLOEXEC, Xapian::InMemory::open(), rare, and SOCK_CLOEXEC.

Referenced by ChertDatabaseReplicator::apply_changeset_from_conn(), GlassDatabaseReplicator::apply_changeset_from_conn(), GlassDatabase::compact(), ChertDatabase::compact(), GlassDatabase::get_database_write_lock(), ChertDatabase::get_database_write_lock(), and ~FlintLock().

◆ operator bool()

FlintLock::operator bool ( ) const

Definition at line 71 of file flint_lock.h.

◆ release()

void FlintLock::release ( )

Release the lock.

Definition at line 463 of file flint_lock.cc.

References close().

Referenced by GlassDatabase::close(), ChertDatabase::close(), GlassDatabase::compact(), and ~FlintLock().

◆ test()

bool FlintLock::test ( ) const

Test if the lock is held.

If this object holds the lock, just returns true. Otherwise it will try to test taking the lock, if that is possible to do on the current platform without actually take it (fcntl() locks support this).

Throws Xapian::UnimplemenetedError if the platform doesn't support testing the lock in this way, or Xapian::DatabaseLockError if there's an error while trying to perform the test.

Definition at line 75 of file flint_lock.cc.

References close(), O_CLOEXEC, Xapian::InMemory::open(), and throw_cannot_test_lock().

Referenced by GlassDatabase::locked(), ChertDatabase::locked(), and ~FlintLock().

◆ throw_databaselockerror()

void FlintLock::throw_databaselockerror ( FlintLock::reason  why,
const std::string &  db_dir,
const std::string &  explanation 
) const

Member Data Documentation

◆ fd

int FlintLock::fd = -1

Definition at line 46 of file flint_lock.h.

◆ filename

std::string FlintLock::filename

Definition at line 40 of file flint_lock.h.

◆ pid

pid_t FlintLock::pid

Definition at line 47 of file flint_lock.h.

The documentation for this class was generated from the following files: