# DB_ENV->lock_get

`

###

    #include <db.h>

    int
    DB_ENV->lock_get(DB_ENV *env, u_int32_t locker,
        u_int32_t flags, const DBT *obj,
        const db_lockmode_t lock_mode, DB_LOCK *lock);

# Description

The DB_ENV->lock_get function acquires a lock from the lock table, returning information about it in the lock argument.

The locker argument specified to DB_ENV->lock_get is an unsigned 32-bit integer quantity. It represents the entity requesting or releasing the lock.

The flags value 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 immediately instead of waiting for the lock to become available.

The obj argument is an untyped byte string that specifies the object to be locked or released. 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 for more information.

The mode argument is used as an index into the environment's lock conflict matrix. When using the default lock conflict matrix, 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 DB_ENV->set_lk_conflicts and Standard Lock Modes for more information on the lock conflict matrix.

If a lock is requested that cannot be immediately granted, and the flags parameter was set to DB_LOCK_NOWAIT, the DB_ENV->lock_get function may return DB_LOCK_NOTGRANTED.

Otherwise, the DB_ENV->lock_get function returns a non-zero error value on failure and 0 on success.

# Errors

The DB_ENV->lock_get function may fail and return a non-zero error for the following conditions:

DB_LOCK_DEADLOCK
  The operation was selected to resolve a deadlock.

EINVAL
  An invalid flag value or parameter was specified.

ENOMEM
  The maximum number of locks has been reached.

The DB_ENV->lock_get function may fail and return a non-zero error for errors specified for other Berkeley DB and C library or system functions. If a catastrophic error has occurred, the DB_ENV->lock_get function may fail and return DB_RUNRECOVERY, in which case all subsequent Berkeley DB calls will fail in the same way.

# See Also

DB_ENV->set_lk_conflicts, DB_ENV->set_lk_detect, DB_ENV->set_lk_max_lockers, DB_ENV->set_lk_max_locks, DB_ENV->set_lk_max_objects, DB_ENV->lock_detect, DB_ENV->lock_get, DB_ENV->lock_id, DB_ENV->lock_id_free, DB_ENV->lock_put, DB_ENV->lock_stat, and DB_ENV->lock_vec.`

Copyright Sleepycat Software