1
<!--$Id: lock_vec.so,v 10.69 2004/08/13 03:38:57 bostic Exp $-->
2
<!--Copyright 1997-2004 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
4
<!--See the file LICENSE for redistribution information.-->
7
<title>Berkeley DB: DbEnv::lock_vec</title>
8
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
12
<table width="100%"><tr valign=top>
14
<h3>DbEnv::lock_vec</h3>
17
<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a>
18
<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td>
23
#include <db_cxx.h>
26
DbEnv::lock_vec(u_int32_t locker, u_int32_t flags,
27
DB_LOCKREQ list[], int nlist, DB_LOCKREQ **elistp);
30
<h3>Description: DbEnv::lock_vec</h3>
31
<p>The DbEnv::lock_vec method atomically obtains and releases one or more locks
32
from the lock table. The DbEnv::lock_vec method is intended to support
33
acquisition or trading of multiple locks under one lock table semaphore,
34
as is needed for lock coupling or in multigranularity locking for lock
36
<p>If any of the requested locks cannot be acquired, or any of the locks to
37
be released cannot be released, the operations before the failing
38
operation are guaranteed to have completed successfully, and
39
DbEnv::lock_vec returns a non-zero value. In addition, if
40
<b>elistp</b> is not NULL, it is set to point to the DB_LOCKREQ entry
41
that was being processed when the error occurred.</p>
42
<p>Unless otherwise specified, the DbEnv::lock_vec method
43
either returns a non-zero error value
44
or throws an exception that encapsulates a non-zero error value on
45
failure, and returns 0 on success.
49
<dt><b>elistp</b><dd>If an error occurs, and the <b>elistp</b> parameter is non-NULL, it
50
is set to point to the DB_LOCKREQ entry that was being processed when
52
<dt><b>flags</b><dd>The <b>flags</b> parameter must be set to 0 or
55
<dt><a name="DB_LOCK_NOWAIT">DB_LOCK_NOWAIT</a><dd>If a lock cannot be granted because the requested lock conflicts with
57
return DB_LOCK_NOTGRANTED or throw a
58
<a href="../api_cxx/lockng_class.html">DbLockNotGrantedException</a> immediately instead of waiting for
59
the lock to become available. In this case, if non-NULL,
60
<b>elistp</b> identifies the request that was not granted, or, if an
61
exception is thrown, the index of the request that was not granted can
62
be found by calling DbLockNotGrantedException.get_index.
64
<dt><b>locker</b><dd>The <b>locker</b> parameter is an unsigned 32-bit integer quantity. It
65
represents the entity requesting or releasing the lock.
66
<dt><b>list</b><dd>The <b>list</b> array provided to DbEnv::lock_vec is typedef'd as
68
<p>To ensure compatibility with future releases of Berkeley DB, all
69
fields of the DB_LOCKREQ structure that are not explicitly set should
70
be initialized to 0 before the first time the structure is used. Do
71
this by declaring the structure external or static, or by calling
73
<p>A DB_LOCKREQ structure has at least the following fields:</p>
75
<dt>lockop_t <a name="op">op</a>;<dd>The operation to be performed, which must be set to one of the
78
<dt><a name="DB_LOCK_GET">DB_LOCK_GET</a><dd>Get the lock defined by the values of the <b>mode</b> and <b>obj</b>
79
structure fields, for the specified <b>locker</b>. Upon return from
80
DbEnv::lock_vec, if the <b>lock</b> field is non-NULL, a reference
81
to the acquired lock is stored there. (This reference is invalidated
82
by any call to DbEnv::lock_vec or <a href="../api_cxx/lock_put.html">DbEnv::lock_put</a> that releases the
84
<dt><a name="DB_LOCK_GET_TIMEOUT">DB_LOCK_GET_TIMEOUT</a><dd>Identical to DB_LOCK_GET except that the value in the <b>timeout</b>
85
structure field overrides any previously specified timeout value for
86
this lock. A value of 0 turns off any previously specified timeout.
87
<dt><a name="DB_LOCK_PUT">DB_LOCK_PUT</a><dd>The lock to which the <b>lock</b> structure field refers is released.
88
The <b>locker</b> parameter, and <b>mode</b> and <b>obj</b> fields
90
<dt><a name="DB_LOCK_PUT_ALL">DB_LOCK_PUT_ALL</a><dd>All locks held by the specified <b>locker</b> are released. The
91
<b>lock</b>, <b>mode</b>, and <b>obj</b> structure fields are
92
ignored. Locks acquired in operations performed by the current call to
93
DbEnv::lock_vec which appear before the DB_LOCK_PUT_ALL
94
operation are released; those acquired in operations appearing after
95
the DB_LOCK_PUT_ALL operation are not released.
96
<dt><a name="DB_LOCK_PUT_OBJ">DB_LOCK_PUT_OBJ</a><dd>All locks held on <b>obj</b> are released. The <b>locker</b>
97
parameter and the <b>lock</b> and <b>mode</b> structure fields are
98
ignored. Locks acquired in operations performed by the current call to
99
DbEnv::lock_vec that appear before the DB_LOCK_PUT_OBJ
100
operation are released; those acquired in operations appearing after the
101
DB_LOCK_PUT_OBJ operation are not released.
102
<dt><a name="DB_LOCK_TIMEOUT">DB_LOCK_TIMEOUT</a><dd>Cause the specified <b>locker</b> to timeout immediately. If the
103
database environment has not configured automatic deadlock detection,
104
the transaction will timeout the next time deadlock detection is
105
performed. As transactions acquire locks on behalf of a single locker
106
ID, timing out the locker ID associated with a transaction will time
107
out the transaction itself.
109
<dt>DB_LOCK <a name="lock">lock</a>;<dd>A lock reference.
110
<dt>const lockmode_t <a name="mode">mode</a>;<dd>The lock mode, used as an index into the environment's lock conflict matrix.
111
When using the default lock conflict matrix, <b>mode</b> must be set to one
112
of the following values:
114
<dt><a name="DB_LOCK_READ">DB_LOCK_READ</a><dd>read (shared)
115
<dt><a name="DB_LOCK_WRITE">DB_LOCK_WRITE</a><dd>write (exclusive)
116
<dt><a name="DB_LOCK_IWRITE">DB_LOCK_IWRITE</a><dd>intention to write (shared)
117
<dt><a name="DB_LOCK_IREAD">DB_LOCK_IREAD</a><dd>intention to read (shared)
118
<dt><a name="DB_LOCK_IWR">DB_LOCK_IWR</a><dd>intention to read and write (shared)
120
<p>See <a href="../api_cxx/env_set_lk_conflicts.html">DbEnv::set_lk_conflicts</a> and <a href="../ref/lock/stdmode.html">Standard Lock Modes</a> for more information on the lock conflict matrix.</p>
121
<dt>const Dbt <a name="obj">obj</a>;<dd>An untyped byte string that specifies the object to be locked or
122
released. Applications using the locking subsystem directly while also
123
doing locking via the Berkeley DB access methods must take care not to
124
inadvertently lock objects that happen to be equal to the unique file
125
IDs used to lock files. See <a href="../ref/lock/am_conv.html">Access
126
method locking conventions</a> for more information.
127
<dt>u_int32_t timeout;<dd>The lock timeout value.
129
<dt><b>nlist</b><dd>The <b>nlist</b> parameter specifies the number of elements in the
133
<p>The DbEnv::lock_vec method
135
<a href="../api_cxx/except_class.html">DbException</a>,
136
encapsulating one of the following non-zero errors, or return one of
137
the following non-zero errors:</p>
140
invalid flag value or parameter was specified.
142
<p>If a transactional database environment operation was selected to
143
resolve a deadlock, the DbEnv::lock_vec method will fail and
144
either return <a href="../ref/program/errorret.html#DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a> or
145
throw a <a href="../api_cxx/deadlock_class.html">DbDeadlockException</a> exception.</p>
146
<p>If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable
147
to grant a lock in the allowed time, the DbEnv::lock_vec method will fail and
148
either return <a href="../ref/program/errorret.html#DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> or
149
throw a <a href="../api_cxx/lockng_class.html">DbLockNotGrantedException</a> exception.</p>
150
<p>If the <a href="../api_cxx/lock_vec.html#DB_LOCK_NOWAIT">DB_LOCK_NOWAIT</a> flag or lock timers were configured and the lock could not be granted before the wait-time expired,
151
the DbEnv::lock_vec method will fail and
152
either return DB_LOCK_NOTGRANTED or
153
throw a <a href="../api_cxx/lockng_class.html">DbLockNotGrantedException</a> exception.</p>
154
<p>If the maximum number of locks has been reached, the DbEnv::lock_vec method will fail and
155
either return ENOMEM or
156
throw a DbMemoryException.</p>
159
<a href="../api_cxx/env_class.html">DbEnv</a>, <a href="../api_cxx/lock_class.html">DbLock</a>
161
<a href="../api_cxx/lock_list.html">Locking Subsystem and Related Methods</a>
163
<table width="100%"><tr><td><br></td><td align=right>
164
<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a>
166
<p><font size=1><a href="../sleepycat/legal.html">Copyright (c) 1996-2004</a> <a href="http://www.sleepycat.com">Sleepycat Software, Inc.</a> - All rights reserved.</font>