The Locking Group contain the API for using the various lock types: exclusive, partition, and shared.
More...
|
int | mdbm_islocked (MDBM *db) |
| Returns whether or not MDBM is locked by another process or thread (thread: V3 only). More...
|
|
int | mdbm_isowned (MDBM *db) |
| Returns whether or not MDBM is currently locked (owned) by the calling process. More...
|
|
uint32_t | mdbm_get_lockmode (MDBM *db) |
| Gets the MDBM's lock mode. More...
|
|
int | mdbm_lock (MDBM *db) |
| Locks the database for exclusive access by the caller. More...
|
|
int | mdbm_unlock (MDBM *db) |
| Unlocks the database, releasing exclusive or shared access by the caller. More...
|
|
int | mdbm_trylock (MDBM *db) |
| Attempts to exclusively lock an MDBM. More...
|
|
int | mdbm_plock (MDBM *db, const datum *key, int flags) |
| Locks a specific partition in the database for exclusive access by the caller. More...
|
|
int | mdbm_punlock (MDBM *db, const datum *key, int flags) |
| Unlocks a specific partition in the database, releasing exclusive access by the caller. More...
|
|
int | mdbm_tryplock (MDBM *db, const datum *key, int flags) |
| Tries to locks a specific partition in the database for exclusive access by the caller. More...
|
|
int | mdbm_lock_shared (MDBM *db) |
| Locks the database for shared access by readers, excluding access to writers. More...
|
|
int | mdbm_trylock_shared (MDBM *db) |
| Locks the database for shared access by readers, excluding access to writers. More...
|
|
int | mdbm_lock_smart (MDBM *db, const datum *key, int flags) |
| Perform either partition, shared or exclusive locking based on the locking-related flags supplied to mdbm_open. More...
|
|
int | mdbm_trylock_smart (MDBM *db, const datum *key, int flags) |
| Attempts to lock an MDBM based on the locking flags supplied to mdbm_open. More...
|
|
int | mdbm_unlock_smart (MDBM *db, const datum *key, int flags) |
| Unlock an MDBM based on the locking flags supplied to mdbm_open. More...
|
|
int | mdbm_lock_reset (const char *dbfilename, int flags) |
| Resets the global lock ownership state of a database. More...
|
|
int | mdbm_delete_lockfiles (const char *dbname) |
| Removes all lockfiles associated with an MDBM file. More...
|
|
The Locking Group contain the API for using the various lock types: exclusive, partition, and shared.
#define MDBM_LOCKMODE_UNKNOWN 0xFFFFFFFF |
Returned by mdbm_get_lockmode for an unknown lock mode (MDBM V2).
#define MDBM_LOCKMODE_UNKNOWN 0xFFFFFFFF |
Returned by mdbm_get_lockmode for an unknown lock mode (MDBM V2).
int mdbm_islocked |
( |
MDBM * |
db | ) |
|
Returns whether or not MDBM is locked by another process or thread (thread: V3 only).
- Parameters
-
[in,out] | db | Database handle |
- Returns
- Locked status
- Return values
-
0 | Database is not locked |
1 | Database is locked |
int mdbm_isowned |
( |
MDBM * |
db | ) |
|
Returns whether or not MDBM is currently locked (owned) by the calling process.
Owned MDBMs have multiple nested locks in place.
- Parameters
-
[in,out] | db | Database handle |
- Returns
- Owned status
- Return values
-
0 | Database is not owned |
1 | Database is owned |
uint32_t mdbm_get_lockmode |
( |
MDBM * |
db | ) |
|
Gets the MDBM's lock mode.
- Parameters
-
[in,out] | db | Database handle |
- Returns
- Lock mode
- Return values
-
0 | - Exclusive locking |
MDBM_OPEN_NOLOCK | - No locking |
MDBM_PARTITIONED_LOCKS | - Partitioned locking |
MDBM_RW_LOCKS | - Shared (read-write) locking |
int mdbm_lock |
( |
MDBM * |
db | ) |
|
Locks the database for exclusive access by the caller.
The lock is nestable, so a caller already holding the lock may call mdbm_lock again as long as an equal number of calls to mdbm_unlock are made to release the lock.
- Parameters
-
[in,out] | db | Database handle |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set. Typically, an error occurs if the database has been corrupted. |
1 | Success, exclusive lock was acquired |
int mdbm_unlock |
( |
MDBM * |
db | ) |
|
Unlocks the database, releasing exclusive or shared access by the caller.
If the caller has called mdbm_lock or mdbm_lock_shared multiple times in a row, an equal number of unlock calls are required. See mdbm_lock and mdbm_lock_shared for usage.
- Parameters
-
[in,out] | db | Database to be unlocked |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set. Typically, an error occurs if the database has been corrupted, or the process/thread does not own the lock. |
1 | Success, exclusive lock was released |
int mdbm_trylock |
( |
MDBM * |
db | ) |
|
Attempts to exclusively lock an MDBM.
- Parameters
-
[in,out] | db | Database handle |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set |
1 | Success, exclusive lock was acquired |
int mdbm_plock |
( |
MDBM * |
db, |
|
|
const datum * |
key, |
|
|
int |
flags |
|
) |
| |
Locks a specific partition in the database for exclusive access by the caller.
The lock is nestable, so a caller already holding the lock may call mdbm_plock again as long as an equal number of calls to mdbm_punlock are made to release the lock.
- Parameters
-
[in,out] | db | Database to be locked. |
[in] | key | Key to be hashed to determine page to lock |
[in] | flags | Ignored. |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set. Typically, an error occurs if the database has been corrupted. |
1 | Success, partition lock was acquired |
int mdbm_punlock |
( |
MDBM * |
db, |
|
|
const datum * |
key, |
|
|
int |
flags |
|
) |
| |
Unlocks a specific partition in the database, releasing exclusive access by the caller.
If the caller has called mdbm_plock multiple times in a row, an equal number of unlock calls are required. See mdbm_plock for usage.
- Parameters
-
[in,out] | db | Database to be unlocked |
[in] | key | Ignored. |
[in] | flags | Ignored. |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set. Typically, an error occurs if the database has been corrupted, or mdbm_plock is called without holding the lock |
1 | Success, partition lock was released |
int mdbm_tryplock |
( |
MDBM * |
db, |
|
|
const datum * |
key, |
|
|
int |
flags |
|
) |
| |
Tries to locks a specific partition in the database for exclusive access by the caller.
The lock is nestable, so a caller already holding the lock may call mdbm_plock again as long as an equal number of calls to mdbm_punlock are made to release the lock. See mdbm_plock for usage.
- Parameters
-
[in,out] | db | Database to be unlocked |
[in] | key | Key to be hashed to determine page to lock |
[in] | flags | Ignored. |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set. Partition is not locked. Typically, an error occurs if the database has been corrupted. |
1 | Success, partition lock was acquired |
int mdbm_lock_shared |
( |
MDBM * |
db | ) |
|
Locks the database for shared access by readers, excluding access to writers.
This is multiple-readers, one writer (MROW) locking. The database must be opened with the MDBM_RW_LOCKS flag to enable shared locks. Use mdbm_unlock to release a shared lock.
Write access (ex. mdbm_store and mdbm_delete) must not be done in the context of a shared lock. Write access must be done in the context of an exclusive lock (mdbm_lock and mdbm_unlock).
The lock is nestable, so a caller already holding the lock may call mdbm_lock_shared again as long as an equal number of calls to mdbm_unlock are made to release the lock.
- Parameters
-
[in,out] | db | Database handle |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set. Typically, an error occurs if the database has been corrupted. |
1 | Success, shared lock was acquired |
int mdbm_trylock_shared |
( |
MDBM * |
db | ) |
|
Locks the database for shared access by readers, excluding access to writers.
This is the non-blocking version of mdbm_lock_shared
This is MROW locking. The database must be opened with the MDBM_RW_LOCKS flag to enable shared locks.
Write access (ex. mdbm_store and mdbm_delete) must not be done in the context of a shared lock. Write access must be done in the context of an exclusive lock (mdbm_lock and mdbm_unlock).
- Parameters
-
[in,out] | db | Database handle |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set. Typically, an error occurs if the database has been corrupted, or the database is already exclusively locked. |
1 | Success, shared lock was acquired |
int mdbm_lock_smart |
( |
MDBM * |
db, |
|
|
const datum * |
key, |
|
|
int |
flags |
|
) |
| |
Perform either partition, shared or exclusive locking based on the locking-related flags supplied to mdbm_open.
- Parameters
-
[in,out] | db | Database handle |
[in] | key | Key to be hashed to determine which page to lock (if needed) |
[in] | flags | MDBM_O_RDWR means lock to perform a write |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set. Typically, an error occurs if the database has been corrupted. |
1 | Success, smart lock was acquired, or db was opened with MDBM_OPEN_NOLOCK. |
int mdbm_trylock_smart |
( |
MDBM * |
db, |
|
|
const datum * |
key, |
|
|
int |
flags |
|
) |
| |
Attempts to lock an MDBM based on the locking flags supplied to mdbm_open.
- Parameters
-
[in,out] | db | Database handle |
[in] | key | Key to be hashed to determine page to lock (if needed) |
[in] | flags | MDBM_O_RDWR means lock to perform a write. |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set |
1 | Success, smart lock was acquired, or db was opened with MDBM_OPEN_NOLOCK. |
int mdbm_unlock_smart |
( |
MDBM * |
db, |
|
|
const datum * |
key, |
|
|
int |
flags |
|
) |
| |
Unlock an MDBM based on the locking flags supplied to mdbm_open.
- Parameters
-
[in,out] | db | Database handle |
[in] | key | Key to be hashed to determine page to lock (if needed) |
[in] | flags | Reserved for future use |
- Returns
- Lock status
- Return values
-
-1 | Error, and errno is set |
1 | Success, smart lock was released, or db was opened with MDBM_OPEN_NOLOCK. |
int mdbm_lock_reset |
( |
const char * |
dbfilename, |
|
|
int |
flags |
|
) |
| |
Resets the global lock ownership state of a database.
USE THIS FUNCTION WITH EXTREME CAUTION! The global lock ownership state of an MDBM is visible to other processes and is reset system-wide. Resetting a lock state while other threads/processes are accessing this database might cause those operations to fail.
- Parameters
-
[in] | dbfilename | Database file name |
[in] | flags | Reserved for future use, and must be 0. |
- Returns
- Lock reset status
- Return values
-
-1 | Error, and errno is set |
0 | Success |
int mdbm_delete_lockfiles |
( |
const char * |
dbname | ) |
|
Removes all lockfiles associated with an MDBM file.
USE THIS FUNCTION WITH EXTREME CAUTION! NOTE: This is only intended to clean-up lockfiles when removing an MDBM file. This function can only be used when all processes that access the MDBM whose locks are being deleted are not running. Calling it on an MDBM still in use will cause corruption and undefined behavior. Deleting lockfiles resets lock ownership and locking mode (exclusive/partition/shared).
- Parameters
-
[in] | dbname | Full path of MDBM file |
- Returns
- Lockfile deletion status
- Return values
-
-1 | Error, and errno is set |
0 | Success |