Berkeley DB: DbLockTab::vec
Полезная информация

DbLockTab::vec


#include <db_cxx.h>

int DbLockTab::vec(u_int32_t locker, u_int32_t flags, DB_LOCKREQ list[], int nlist, DB_LOCKREQ **elistp);

Description

The DbLockTab::vec method atomically obtains and releases one or more locks from the lock table. The DbLockTab::vec method is intended to support acquisition or trading of multiple locks under one lock table semaphore, as is needed for lock coupling or in multigranularity locking for lock escalation.

The locker argument specified to DbLockTab::vec 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 list array provided to DbLockTab::vec is typedef'd as DB_LOCKREQ. A DB_LOCKREQ structure has at least the following fields, which must be initialized before calling DbLockTab::vec:

lockop_t op;
The operation to be performed, which must be set to one of the following values:

DB_LOCK_GET
Get a lock, as defined by the values of locker, obj, and mode. Upon return from DbLockTab::vec, if the lock field is non-NULL, a reference to the acquired lock is stored there. (This reference is invalidated by any call to DbLockTab::vec or DbLock::put that releases the lock.)

DB_LOCK_PUT
The lock referenced by the contents of the lock field is released.

DB_LOCK_PUT_ALL
All locks held by the locker are released. (Any locks acquired as a part of the current call to DbLockTab::vec that appear after the DB_LOCK_PUT_ALL entry are not considered for this operation).

DB_LOCK_PUT_OBJ
All locks held by the locker, on the object obj, with the mode specified by lock_mode, are released. A lock_mode of DB_LOCK_NG indicates that all locks on the object should be released. Note that any locks acquired as a part of the current call to DbLockTab::vec that occur before the DB_LOCK_PUT_OBJ will also be released; those acquired afterwards will not be released.

const Dbt obj;
An untyped byte string that specifies the object to be locked or released.

const lockmode_t mode;
The lock mode, used as an index into lt's conflict array.

DB_LOCK lock;
A lock reference.

The nlist argument specifies the number of elements in the list array.

If any of the requested locks cannot be acquired, or any of the locks to be released cannot be released, the operations before the failing operation are guaranteed to have completed successfully, and DbLockTab::vec returns a non-zero value. In addition, if elistp is not NULL, it is set to point to the DB_LOCKREQ entry that was being processed when the error occurred.

In the case of an error, DbLockTab::vec may return one of the following values:

DB_LOCK_DEADLOCK
The specified locker was selected as a victim in order to resolve a deadlock.

DB_LOCK_NOTHELD
The lock cannot be released, as it was not held by the locker.

DB_LOCK_NOTGRANTED
A lock was requested that could not be granted and the flag parameter was set to DB_LOCK_NOWAIT. In this case, if non-NULL, elistp identifies the request that was granted.

Otherwise, the DbLockTab::vec method either returns errno or throws an exception that encapsulates an errno on failure, and 0 on success.

Errors

If a fatal error occurs in Berkeley DB, the DbLockTab::vec method may fail and either return DB_RUNRECOVERY or throw an exception encapsulating DB_RUNRECOVERY, at which point all subsequent database calls will also fail in the same way. Methods marked as returning errno will, by default, throw an exception that encapsulates the error information. The default error behavior can be changed, see
DbException.

The DbLockTab::vec method may fail and throw an exception for any of the errors specified for the following Berkeley DB and C library functions: abort(3), fcntl(3), fflush(3), fprintf(3), fsync(3), getpid(3), isprint(3), DbLockTab::detect, lseek(3), memcpy(3), memset(3), mmap(3), munmap(3), printf(3), pstat_getdynamic(3), shmat(3), shmdt(3), strerror(3), sysconf(3), vfprintf(3), vsnprintf(3), and write(3).

In addition, the DbLockTab::vec method may fail and throw an exception or return errno for the following conditions:

EACCES
An attempt was made to release lock held by another locker.

EINVAL
An invalid flag value or parameter was specified.

Class

DbLockTab

See Also

DbLockTab::close, DbLockTab::detect, DbLockTab::get, DbLockTab::id, DbLockTab::open, DbLockTab::stat DbLockTab::unlink and DbLockTab::vec.