DbEnv::lock_get()

#include <db_cxx.h>
 
int
DbEnv::lock_get(u_int32_t locker, u_int32_t flags,
    const Dbt *object, const db_lockmode_t lock_mode, DbLock *lock);

The DbEnv::lock_get() method acquires a lock from the lock table, returning information about it in the lock parameter.

The DbEnv::lock_get() method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

Parameters

locker

The locker parameter is an unsigned 32-bit integer quantity. It represents the entity requesting the lock.

flags

The flags parameter must be set to 0 or the following value:

  • DB_LOCK_NOWAIT

    If a lock cannot be granted because the requested lock conflicts with an existing lock, return DB_LOCK_NOTGRANTED immediately instead of waiting for the lock to become available.

object

The object parameter is an untyped byte string that specifies the object to be locked. Applications using the locking subsystem directly while also doing locking via the Berkeley DB access methods must take care not to inadvertently lock objects that happen to be equal to the unique file IDs used to lock files. See Access method locking conventions in the Berkeley DB Programmer's Reference Guide for more information.

lock_mode

The lock_mode parameter is used as an index into the environment's lock conflict matrix. When using the default lock conflict matrix, lock_mode must be set to one of the following values:

  • DB_LOCK_READ

    read (shared)

  • DB_LOCK_WRITE

    write (exclusive)

  • DB_LOCK_IWRITE

    intention to write (shared)

  • DB_LOCK_IREAD

    intention to read (shared)

  • DB_LOCK_IWR

    intention to read and write (shared)

See DbEnv::set_lk_conflicts() and Standard Lock Modes for more information on the lock conflict matrix.

lock

The DbEnv::lock_get() method returns the lock information in lock.

Errors

The DbEnv::lock_get() method may fail and throw a DbException exception, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:

DbDeadlockException or DB_LOCK_DEADLOCK

A transactional database environment operation was selected to resolve a deadlock.

DbDeadlockException is thrown if your Berkeley DB API is configured to throw exceptions. Otherwise, DB_LOCK_DEADLOCK is returned.

DbLockNotGrantedException or DB_LOCK_NOTGRANTED

A Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable to grant a lock in the allowed time.

You attempted to open a database handle that is configured for no waiting exclusive locking, but the exclusive lock could not be immediately obtained. See Db::set_lk_exclusive() for more information.

DbLockNotGrantedException is thrown if your Berkeley DB API is configured to throw exceptions. Otherwise, DB_LOCK_NOTGRANTED is returned.

DbLockNotGrantedException or DB_LOCK_NOTGRANTED

The DB_LOCK_NOWAIT flag or lock timers were configured and the lock could not be granted before the wait-time expired.

DbLockNotGrantedException is thrown if your Berkeley DB API is configured to throw exceptions. Otherwise, DB_LOCK_NOTGRANTED is returned.

EINVAL

An invalid flag value or parameter was specified.

EINVAL

The method was called on an environment which had been opened without being configured for locking.

ENOMEM

The maximum number of locks has been reached.

Class

DbEnv, DbLock

See Also

Locking Subsystem and Related Methods