xapian-core
1.4.27
|
#include <flint_lock.h>
Public Types | |
enum | reason { SUCCESS, INUSE, UNSUPPORTED, FDLIMIT, UNKNOWN } |
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 |
Definition at line 39 of file flint_lock.h.
enum FlintLock::reason |
Enumerator | |
---|---|
SUCCESS | |
INUSE | |
UNSUPPORTED | |
FDLIMIT | |
UNKNOWN |
Definition at line 51 of file flint_lock.h.
|
inlineexplicit |
Standard constructor.
Definition at line 60 of file flint_lock.h.
|
inline |
Constructor for use in read-only cases (like single-file glass).
Definition at line 69 of file flint_lock.h.
|
inline |
Definition at line 80 of file flint_lock.h.
References lock(), release(), test(), and throw_databaselockerror().
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.
exclusive | Get an exclusive lock? Value currently ignored, and the lock is always exclusive. |
wait | Wait 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, SOCK_CLOEXEC, and usual.
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().
|
inline |
Definition at line 71 of file flint_lock.h.
void FlintLock::release | ( | ) |
Release the lock.
Definition at line 459 of file flint_lock.cc.
References close().
Referenced by GlassDatabase::close(), ChertDatabase::close(), GlassDatabase::compact(), and ~FlintLock().
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().
void FlintLock::throw_databaselockerror | ( | FlintLock::reason | why, |
const std::string & | db_dir, | ||
const std::string & | explanation | ||
) | const |
Throw Xapian::DatabaseLockError.
Definition at line 495 of file flint_lock.cc.
References FDLIMIT, INUSE, UNKNOWN, and UNSUPPORTED.
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().
|
private |
Definition at line 46 of file flint_lock.h.
|
private |
Definition at line 40 of file flint_lock.h.
|
private |
Definition at line 47 of file flint_lock.h.