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