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">
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>DbEnv::lock_get()</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="lockdetect.html" title="DbEnv::lock_detect()" />
12 <link rel="next" href="lockid.html" title="DbEnv::lock_id()" />
15 <div xmlns="" class="navheader">
17 <p>Library Version 11.2.5.3</p>
19 <table width="100%" summary="Navigation header">
21 <th colspan="3" align="center">DbEnv::lock_get()</th>
24 <td width="20%" align="left"><a accesskey="p" href="lockdetect.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 7.
28 <td width="20%" align="right"> <a accesskey="n" href="lockid.html">Next</a></td>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
37 <h2 class="title" style="clear: both"><a id="lockget"></a>DbEnv::lock_get()</h2>
41 <pre class="programlisting">#include <db_cxx.h>
44 DbEnv::lock_get(u_int32_t locker, u_int32_t flags,
45 const Dbt *object, const db_lockmode_t lock_mode, DbLock *lock);</pre>
47 The <code class="methodname">DbEnv::lock_get()</code> method acquires a lock from the lock table,
48 returning information about it in the <span class="bold"><strong>lock</strong></span> parameter.
51 The <code class="methodname">DbEnv::lock_get()</code> <span>
54 method either returns a non-zero error value or throws an
55 exception that encapsulates a non-zero error value on
56 failure, and returns 0 on success.
60 <div class="sect2" lang="en" xml:lang="en">
61 <div class="titlepage">
64 <h3 class="title"><a id="idp2682624"></a>Parameters</h3>
68 <div class="sect3" lang="en" xml:lang="en">
69 <div class="titlepage">
72 <h4 class="title"><a id="idp2639640"></a>locker</h4>
77 The <span class="bold"><strong>locker</strong></span> parameter is an unsigned
78 32-bit integer quantity. It represents the entity requesting the
82 <div class="sect3" lang="en" xml:lang="en">
83 <div class="titlepage">
86 <h4 class="title"><a id="idp2675576"></a>flags</h4>
91 The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
92 or the following value:
94 <div class="itemizedlist">
97 <p><a id="get_DB_LOCK_NOWAIT"></a>
98 <code class="literal">DB_LOCK_NOWAIT</code>
101 If a lock cannot be granted because the requested lock conflicts with
102 an existing lock, return DB_LOCK_NOTGRANTED immediately instead of
103 waiting for the lock to become available.
109 <div class="sect3" lang="en" xml:lang="en">
110 <div class="titlepage">
113 <h4 class="title"><a id="idp2698488"></a>object</h4>
118 The <span class="bold"><strong>object</strong></span> parameter is an untyped
119 byte string that specifies the object to be locked. Applications
120 using the locking subsystem directly while also doing locking via the
121 Berkeley DB access methods must take care not to inadvertently lock
122 objects that happen to be equal to the unique file IDs used to lock
123 files. See <a href="../../programmer_reference/lock_am_conv.html" class="olink">Access method
124 locking conventions</a> in the <em class="citetitle">Berkeley DB Programmer's Reference Guide</em>
125 for more information.
128 <div class="sect3" lang="en" xml:lang="en">
129 <div class="titlepage">
132 <h4 class="title"><a id="idp2701472"></a>lock_mode</h4>
137 The <span class="bold"><strong>lock_mode</strong></span> parameter is used as an
138 index into the environment's lock conflict matrix. When using the
139 default lock conflict matrix, <span class="bold"><strong>lock_mode</strong></span> must be set to one of the following
142 <div class="itemizedlist">
146 <code class="literal">DB_LOCK_READ</code>
154 <code class="literal">DB_LOCK_WRITE</code>
162 <code class="literal">DB_LOCK_IWRITE</code>
165 intention to write (shared)
170 <code class="literal">DB_LOCK_IREAD</code>
173 intention to read (shared)
178 <code class="literal">DB_LOCK_IWR</code>
181 intention to read and write (shared)
187 See <a class="xref" href="envset_lk_conflicts.html" title="DbEnv::set_lk_conflicts()">DbEnv::set_lk_conflicts()</a>
188 and <a href="../../programmer_reference/lock_stdmode.html" class="olink">Standard Lock Modes</a>
189 for more information on the lock conflict matrix.
192 <div class="sect3" lang="en" xml:lang="en">
193 <div class="titlepage">
196 <h4 class="title"><a id="idp2703744"></a>lock</h4>
201 The <code class="methodname">DbEnv::lock_get()</code>
202 method returns the lock information in <span class="bold"><strong>lock</strong></span>.
206 <div class="sect2" lang="en" xml:lang="en">
207 <div class="titlepage">
210 <h3 class="title"><a id="idp2709056"></a>Errors</h3>
215 The <code class="methodname">DbEnv::lock_get()</code> <span>
218 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a>
219 exception, encapsulating one of the following non-zero errors, or return one
220 of the following non-zero errors:
224 <div class="sect3" lang="en" xml:lang="en">
225 <div class="titlepage">
228 <h4 class="title"><a id="idp2698864"></a><span>DbDeadlockException or </span>DB_LOCK_DEADLOCK</h4>
233 A transactional database environment operation was selected to resolve
237 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
238 your Berkeley DB API is configured to throw exceptions.
239 Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned.
242 <div class="sect3" lang="en" xml:lang="en">
243 <div class="titlepage">
246 <h4 class="title"><a id="idp2701368"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4>
251 A Berkeley DB Concurrent Data Store database environment configured
252 for lock timeouts was unable to grant a lock in the allowed time.
255 You attempted to open a database handle that is configured
256 for no waiting exclusive locking, but the exclusive lock could not be
257 immediately obtained. See
258 <a class="xref" href="dbset_lk_exclusive.html" title="Db::set_lk_exclusive()">Db::set_lk_exclusive()</a>
259 for more information.
262 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if
263 your Berkeley DB API is configured to throw exceptions.
264 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned.
267 <div class="sect3" lang="en" xml:lang="en">
268 <div class="titlepage">
271 <h4 class="title"><a id="idp2686112"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4>
276 The <a class="link" href="lockvec.html#vec_DB_LOCK_NOWAIT">DB_LOCK_NOWAIT</a>
277 flag or lock timers were configured and the lock could not be granted
278 before the wait-time expired.
281 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if
282 your Berkeley DB API is configured to throw exceptions.
283 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned.
286 <div class="sect3" lang="en" xml:lang="en">
287 <div class="titlepage">
290 <h4 class="title"><a id="idp2712248"></a>EINVAL</h4>
295 An invalid flag value or parameter was specified.
298 <div class="sect3" lang="en" xml:lang="en">
299 <div class="titlepage">
302 <h4 class="title"><a id="idp2721168"></a>EINVAL</h4>
307 The method was called on an environment which had been
308 opened without being configured for locking.
311 <div class="sect3" lang="en" xml:lang="en">
312 <div class="titlepage">
315 <h4 class="title"><a id="idp2721640"></a>ENOMEM</h4>
320 The maximum number of locks has been reached.
324 <div class="sect2" lang="en" xml:lang="en">
325 <div class="titlepage">
328 <h3 class="title"><a id="idp2711280"></a>Class</h3>
333 <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a>,
334 <a class="link" href="lock.html" title="Chapter 7. The DbLock Handle">DbLock</a>
337 <div class="sect2" lang="en" xml:lang="en">
338 <div class="titlepage">
341 <h3 class="title"><a id="idp2710088"></a>See Also</h3>
346 <a class="xref" href="lock.html#locklist" title="Locking Subsystem and Related Methods">Locking Subsystem and Related Methods</a>
350 <div class="navfooter">
352 <table width="100%" summary="Navigation footer">
354 <td width="40%" align="left"><a accesskey="p" href="lockdetect.html">Prev</a> </td>
355 <td width="20%" align="center">
356 <a accesskey="u" href="lock.html">Up</a>
358 <td width="40%" align="right"> <a accesskey="n" href="lockid.html">Next</a></td>
361 <td width="40%" align="left" valign="top">DbEnv::lock_detect() </td>
362 <td width="20%" align="center">
363 <a accesskey="h" href="index.html">Home</a>
365 <td width="40%" align="right" valign="top"> DbEnv::lock_id()</td>