1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>DbEnv::lock_vec()</title> 7 <link rel="stylesheet" href="apiReference.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Berkeley DB C++ API Reference" /> 10 <link rel="up" href="lock.html" title="Chapter 7. The DbLock Handle" /> 11 <link rel="prev" href="lockstat_print.html" title="DbEnv::lock_stat_print()" /> 12 <link rel="next" href="lsn.html" title="Chapter 8. The DbLsn Handle" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DbEnv::lock_vec()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="lockstat_print.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 7. 23 The DbLock Handle 24 </th> 25 <td width="20%" align="right"> <a accesskey="n" href="lsn.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="lockvec"></a>DbEnv::lock_vec()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db_cxx.h> 39 40int 41DbEnv::lock_vec(u_int32_t locker, u_int32_t flags, 42 DB_LOCKREQ list[], int nlist, DB_LOCKREQ **elistp);</pre> 43 <p> 44 The <code class="methodname">DbEnv::lock_vec()</code> method atomically obtains and releases one or 45 more locks from the lock table. The <code class="methodname">DbEnv::lock_vec()</code> method is 46 intended to support acquisition or trading of multiple locks under one 47 lock table semaphore, as is needed for lock coupling or in 48 multigranularity locking for lock escalation. 49 </p> 50 <p> 51 If any of the requested locks cannot be acquired, or any of the locks 52 to be released cannot be released, the operations before the failing 53 operation are guaranteed to have completed successfully, and 54 <code class="methodname">DbEnv::lock_vec()</code> returns a non-zero value. In addition, if 55 <span class="bold"><strong>elistp</strong></span> is not NULL, it is set to 56 point to the DB_LOCKREQ entry that was being processed when the error 57 occurred. 58 </p> 59 <p> 60 Unless otherwise specified, the <code class="methodname">DbEnv::lock_vec()</code> <span> 61 62 <span> 63 method either returns a non-zero error value or throws an 64 exception that encapsulates a non-zero error value on 65 failure, and returns 0 on success. 66 </span> 67 </span> 68 </p> 69 <div class="sect2" lang="en" xml:lang="en"> 70 <div class="titlepage"> 71 <div> 72 <div> 73 <h3 class="title"><a id="id1682308"></a>Parameters</h3> 74 </div> 75 </div> 76 </div> 77 <div class="sect3" lang="en" xml:lang="en"> 78 <div class="titlepage"> 79 <div> 80 <div> 81 <h4 class="title"><a id="id1683110"></a>elistp</h4> 82 </div> 83 </div> 84 </div> 85 <p> 86 If an error occurs, and the <span class="bold"><strong>elistp</strong></span> 87 parameter is non-NULL, it is set to point to the DB_LOCKREQ entry that 88 was being processed when the error occurred. 89 </p> 90 </div> 91 <div class="sect3" lang="en" xml:lang="en"> 92 <div class="titlepage"> 93 <div> 94 <div> 95 <h4 class="title"><a id="id1683423"></a>flags</h4> 96 </div> 97 </div> 98 </div> 99 <p> 100 The <span class="bold"><strong>flags</strong></span> parameter must be set to 0 101 or the following value: 102 </p> 103 <div class="itemizedlist"> 104 <ul type="disc"> 105 <li> 106 <p><a id="vec_DB_LOCK_NOWAIT"></a> 107 <code class="literal">DB_LOCK_NOWAIT</code> 108 </p> 109 <p> 110 If a lock cannot be granted because the requested lock conflicts with 111 an existing lock, return DB_LOCK_NOTGRANTED immediately instead of 112 waiting for the lock to become available. In this case, if non-NULL, 113 <span class="bold"><strong>elistp</strong></span> identifies the request that 114 was not granted. 115 </p> 116 </li> 117 </ul> 118 </div> 119 </div> 120 <div class="sect3" lang="en" xml:lang="en"> 121 <div class="titlepage"> 122 <div> 123 <div> 124 <h4 class="title"><a id="id1683577"></a>locker</h4> 125 </div> 126 </div> 127 </div> 128 <p> 129 The <span class="bold"><strong>locker</strong></span> parameter is an unsigned 130 32-bit integer quantity. It represents the entity requesting or 131 releasing the lock. 132 </p> 133 </div> 134 <div class="sect3" lang="en" xml:lang="en"> 135 <div class="titlepage"> 136 <div> 137 <div> 138 <h4 class="title"><a id="id1683037"></a>list</h4> 139 </div> 140 </div> 141 </div> 142 <p> 143 The <span class="bold"><strong>list</strong></span> array provided to 144 <code class="methodname">DbEnv::lock_vec()</code> is typedef'd as DB_LOCKREQ. 145 </p> 146 <p> 147 To ensure compatibility with future releases of Berkeley DB, all 148 fields of the DB_LOCKREQ structure that are not explicitly set should 149 be initialized to 0 before the first time the structure is used. Do 150 this by declaring the structure external or static, or by calling 151 <span class="bold"><strong>memset</strong></span>(3). 152 </p> 153 <p> 154 A DB_LOCKREQ structure has at least the following fields: 155 </p> 156 <div class="itemizedlist"> 157 <ul type="disc"> 158 <li> 159 <p><a id="vec_op"></a> 160 <code class="literal">lockop_t op;</code> 161 </p> 162 <p> 163 The operation to be performed, which must be set to one of the 164 following values: 165 </p> 166 <div class="itemizedlist"> 167 <ul type="circle"> 168 <li> 169 <p><a id="vec_DB_LOCK_GET"></a> 170 <code class="literal">DB_LOCK_GET</code> 171 </p> 172 <p> 173 Get the lock defined by the values of the <span class="bold"><strong>mode</strong></span> and <span class="bold"><strong>obj</strong></span> 174 structure fields, for the specified 175 <span class="bold"><strong>locker</strong></span>. 176 Upon return from <code class="methodname">DbEnv::lock_vec()</code>, 177 if the <span class="bold"><strong>lock</strong></span> field is non-NULL, a 178 reference to the acquired lock is stored there. (This reference is 179 invalidated by any call to <code class="methodname">DbEnv::lock_vec()</code> or 180 <a class="xref" href="lockput.html" title="DbEnv::lock_put()">DbEnv::lock_put()</a> that releases 181 the lock.) 182 </p> 183 </li> 184 <li> 185 <p><a id="vec_DB_LOCK_GET_TIMEOUT"></a> 186 <code class="literal">DB_LOCK_GET_TIMEOUT</code> 187 </p> 188 <p> 189 Identical to DB_LOCK_GET except that the value in the <span class="bold"><strong>timeout</strong></span> structure field overrides any 190 previously specified timeout value for this lock. A value of 0 turns 191 off any previously specified timeout. 192 </p> 193 </li> 194 <li> 195 <p><a id="vec_DB_LOCK_PUT"></a> 196 <code class="literal">DB_LOCK_PUT</code> 197 </p> 198 <p> 199 The lock to which the <span class="bold"><strong>lock</strong></span> structure 200 field refers is released. The <span class="bold"><strong>locker</strong></span> 201 parameter, and <span class="bold"><strong>mode</strong></span> and <span class="bold"><strong>obj</strong></span> fields are ignored. 202 </p> 203 </li> 204 <li> 205 <p><a id="vec_DB_LOCK_PUT_ALL"></a> 206 <code class="literal">DB_LOCK_PUT_ALL</code> 207 </p> 208 <p> 209 All locks held by the specified <span class="bold"><strong>locker</strong></span> are released. The <span class="bold"><strong>lock</strong></span>, <span class="bold"><strong>mode</strong></span>, 210 and <span class="bold"><strong>obj</strong></span> structure fields are ignored. 211 Locks acquired in operations performed by the current call to 212 <code class="methodname">DbEnv::lock_vec()</code> which appear before the DB_LOCK_PUT_ALL operation 213 are released; those acquired in operations appearing after the 214 DB_LOCK_PUT_ALL operation are not released. 215 </p> 216 </li> 217 <li> 218 <p><a id="vec_DB_LOCK_PUT_OBJ"></a> 219 <code class="literal">DB_LOCK_PUT_OBJ</code> 220 </p> 221 <p> 222 All locks held on <span class="bold"><strong>obj</strong></span> are released. 223 The <span class="bold"><strong>locker</strong></span> parameter and the 224 <span class="bold"><strong>lock</strong></span> and <span class="bold"><strong>mode</strong></span> structure fields are ignored. Locks 225 acquired in operations performed by the current call to 226 <code class="methodname">DbEnv::lock_vec()</code> that appear before the DB_LOCK_PUT_OBJ operation 227 are released; those acquired in operations appearing after the 228 DB_LOCK_PUT_OBJ operation are not released. 229 </p> 230 </li> 231 <li> 232 <p><a id="vec_DB_LOCK_TIMEOUT"></a> 233 <code class="literal">DB_LOCK_TIMEOUT</code> 234 </p> 235 <p> 236 Cause the specified <span class="bold"><strong>locker</strong></span> to timeout 237 immediately. If the database environment has not configured automatic 238 deadlock detection, the transaction will timeout the next time 239 deadlock detection is performed. As transactions acquire locks on 240 behalf of a single locker ID, timing out the locker ID associated with 241 a transaction will time out the transaction itself. 242 </p> 243 </li> 244 </ul> 245 </div> 246 </li> 247 <li> 248 <p><a id="vec_lock"></a> 249 <code class="literal">DB_LOCK lock;</code> 250 </p> 251 <p> 252 A lock reference. 253 </p> 254 </li> 255 <li> 256 <p><a id="vec_mode"></a> 257 <code class="literal">const lockmode_t mode;</code> 258 </p> 259 <p> 260 The lock mode, used as an index into the environment's lock conflict 261 matrix. When using the default lock conflict matrix, <span class="bold"><strong>mode</strong></span> must be set to one of the following 262 values: 263 </p> 264 <div class="itemizedlist"> 265 <ul type="circle"> 266 <li> 267 <p><a id="vec_DB_LOCK_READ"></a> 268 <code class="literal">DB_LOCK_READ</code> 269 </p> 270 <p> 271 read (shared) 272 </p> 273 </li> 274 <li> 275 <p><a id="vec_DB_LOCK_WRITE"></a> 276 <code class="literal">DB_LOCK_WRITE</code> 277 </p> 278 <p> 279 write (exclusive) 280 </p> 281 </li> 282 <li> 283 <p><a id="vec_DB_LOCK_IWRITE"></a> 284 <code class="literal">DB_LOCK_IWRITE</code> 285 </p> 286 <p> 287 intention to write (shared) 288 </p> 289 </li> 290 <li> 291 <p><a id="vec_DB_LOCK_IREAD"></a> 292 <code class="literal">DB_LOCK_IREAD</code> 293 </p> 294 <p> 295 intention to read (shared) 296 </p> 297 </li> 298 <li> 299 <p><a id="vec_DB_LOCK_IWR"></a> 300 <code class="literal">DB_LOCK_IWR</code> 301 </p> 302 <p> 303 intention to read and write (shared) 304 </p> 305 </li> 306 </ul> 307 </div> 308 <p> 309 See <a class="xref" href="envset_lk_conflicts.html" title="DbEnv::set_lk_conflicts()">DbEnv::set_lk_conflicts()</a> 310 and <a href="../../programmer_reference/lock_stdmode.html" class="olink">Standard Lock Modes</a> 311 for more information on the lock conflict matrix. 312 </p> 313 </li> 314 <li> 315 <p> 316 <span class="bold"><a id="obj"></a><strong>const DBT obj;</strong></span> 317 </p> 318 <p> 319 An untyped byte string that specifies the object to be locked or 320 released. Applications using the locking subsystem directly while 321 also doing locking via the Berkeley DB access methods must take care 322 not to inadvertently lock objects that happen to be equal to the 323 unique file IDs used to lock files. See 324 <a href="../../programmer_reference/lock_am_conv.html" class="olink">Access method locking 325 conventions</a> in the 326 <em class="citetitle">Berkeley DB Programmer's Reference Guide</em> for more information. 327 </p> 328 </li> 329 <li> 330 <p> 331 <span class="bold"><strong>u_int32_t timeout;</strong></span> 332 </p> 333 <p> 334 The lock timeout value. 335 </p> 336 </li> 337 </ul> 338 </div> 339 </div> 340 <div class="sect3" lang="en" xml:lang="en"> 341 <div class="titlepage"> 342 <div> 343 <div> 344 <h4 class="title"><a id="id1683656"></a>nlist</h4> 345 </div> 346 </div> 347 </div> 348 <p> 349 The <span class="bold"><strong>nlist</strong></span> parameter specifies the 350 number of elements in the <span class="bold"><strong>list</strong></span> array. 351 </p> 352 </div> 353 </div> 354 <div class="sect2" lang="en" xml:lang="en"> 355 <div class="titlepage"> 356 <div> 357 <div> 358 <h3 class="title"><a id="id1684036"></a>Errors</h3> 359 </div> 360 </div> 361 </div> 362 <p> 363 The <code class="methodname">DbEnv::lock_vec()</code> <span> 364 365 <span> 366 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 367 exception, encapsulating one of the following non-zero errors, or return one 368 of the following non-zero errors: 369 </span> 370 </span> 371 </p> 372 <div class="sect3" lang="en" xml:lang="en"> 373 <div class="titlepage"> 374 <div> 375 <div> 376 <h4 class="title"><a id="id1683663"></a><span>DbDeadlockException or </span>DB_LOCK_DEADLOCK</h4> 377 </div> 378 </div> 379 </div> 380 <p> 381 A transactional database environment operation was selected to resolve 382 a deadlock. 383 </p> 384 <p> 385 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if 386 your Berkeley DB API is configured to throw exceptions. 387 Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned. 388 </p> 389 </div> 390 <div class="sect3" lang="en" xml:lang="en"> 391 <div class="titlepage"> 392 <div> 393 <div> 394 <h4 class="title"><a id="id1683955"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4> 395 </div> 396 </div> 397 </div> 398 <p> 399 A Berkeley DB Concurrent Data Store database environment configured 400 for lock timeouts was unable to grant a lock in the allowed time. 401 </p> 402 <p> 403 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if 404 your Berkeley DB API is configured to throw exceptions. 405 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned. 406 </p> 407 </div> 408 <div class="sect3" lang="en" xml:lang="en"> 409 <div class="titlepage"> 410 <div> 411 <div> 412 <h4 class="title"><a id="id1683358"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4> 413 </div> 414 </div> 415 </div> 416 <p> 417 The <a class="link" href="lockvec.html#vec_DB_LOCK_NOWAIT">DB_LOCK_NOWAIT</a> 418 flag or lock timers were configured and the lock could not be granted 419 before the wait-time expired. 420 </p> 421 <p> 422 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if 423 your Berkeley DB API is configured to throw exceptions. 424 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned. 425 </p> 426 </div> 427 <div class="sect3" lang="en" xml:lang="en"> 428 <div class="titlepage"> 429 <div> 430 <div> 431 <h4 class="title"><a id="id1683890"></a>EINVAL</h4> 432 </div> 433 </div> 434 </div> 435 <p> 436 An invalid flag value or parameter was specified. 437 </p> 438 </div> 439 <div class="sect3" lang="en" xml:lang="en"> 440 <div class="titlepage"> 441 <div> 442 <div> 443 <h4 class="title"><a id="id1683561"></a>ENOMEM</h4> 444 </div> 445 </div> 446 </div> 447 <p> 448 The maximum number of locks has been reached. 449 </p> 450 </div> 451 </div> 452 <div class="sect2" lang="en" xml:lang="en"> 453 <div class="titlepage"> 454 <div> 455 <div> 456 <h3 class="title"><a id="id1683505"></a>Class</h3> 457 </div> 458 </div> 459 </div> 460 <p> 461 <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a>, 462 <a class="link" href="lock.html" title="Chapter 7. The DbLock Handle">DbLock</a> 463 </p> 464 </div> 465 <div class="sect2" lang="en" xml:lang="en"> 466 <div class="titlepage"> 467 <div> 468 <div> 469 <h3 class="title"><a id="id1683383"></a>See Also</h3> 470 </div> 471 </div> 472 </div> 473 <p> 474 <a class="xref" href="lock.html#locklist" title="Locking Subsystem and Related Methods">Locking Subsystem and Related Methods</a> 475 </p> 476 </div> 477 </div> 478 <div class="navfooter"> 479 <hr /> 480 <table width="100%" summary="Navigation footer"> 481 <tr> 482 <td width="40%" align="left"><a accesskey="p" href="lockstat_print.html">Prev</a> </td> 483 <td width="20%" align="center"> 484 <a accesskey="u" href="lock.html">Up</a> 485 </td> 486 <td width="40%" align="right"> <a accesskey="n" href="lsn.html">Next</a></td> 487 </tr> 488 <tr> 489 <td width="40%" align="left" valign="top">DbEnv::lock_stat_print() </td> 490 <td width="20%" align="center"> 491 <a accesskey="h" href="index.html">Home</a> 492 </td> 493 <td width="40%" align="right" valign="top"> Chapter 8. 494 The DbLsn Handle 495 </td> 496 </tr> 497 </table> 498 </div> 499 </body> 500</html> 501