Lines Matching refs:lock

50  * ordering for lock access.  However, it does support an optional
56 * to the read and write lock is unspecified, subject to reentrancy
57 * constraints. A nonfair lock that is continuously contended may
59 * will normally have higher throughput than a fair lock.
64 * approximately arrival-order policy. When the currently held lock
66 * be assigned the write lock, or if there is a group of reader threads
68 * assigned the read lock.
70 * <p>A thread that tries to acquire a fair read lock (non-reentrantly)
71 * will block if either the write lock is held, or there is a waiting
72 * writer thread. The thread will not acquire the read lock until
74 * released the write lock. Of course, if a waiting writer abandons
76 * in the queue with the write lock free, then those readers will be
77 * assigned the read lock.
79 * <p>A thread that tries to acquire a fair write lock (non-reentrantly)
80 * will block unless both the read lock and write lock are free (which
83 * do not honor this fair setting and will acquire the lock if it is
90 * <p>This lock allows both readers and writers to reacquire read or
95 * <p>Additionally, a writer can acquire the read lock, but not
99 * write lock it will never succeed.
102 * <p>Reentrancy also allows downgrading from the write lock to a read lock,
103 * by acquiring the write lock, then the read lock and then releasing the
104 * write lock. However, upgrading from a read lock to the write lock is
107 * <li><b>Interruption of lock acquisition</b>
108 * <p>The read lock and write lock both support interruption during lock
112 * <p>The write lock provides a {@link Condition} implementation that
113 * behaves in the same way, with respect to the write lock, as the
116 * This {@link Condition} can, of course, only be used with the write lock.
118 * <p>The read lock does not support a {@link Condition} and
129 * locks: a deserialized lock is in the unlocked state, regardless of
133 * lock downgrading after updating a cache (exception handling is
144 * rwl.readLock().lock();
146 * // Must release read lock before acquiring write lock
148 * rwl.writeLock().lock();
151 * // acquired write lock and changed state before we did.
156 * // Downgrade by acquiring read lock before releasing write lock
157 * rwl.readLock().lock();
187 * r.lock();
192 * r.lock();
197 * w.lock();
202 * w.lock();
210 * <p>This lock supports a maximum of 65535 recursive write locks
240 * @param fair {@code true} if this lock should use a fair ordering policy
261 * The lower one representing the exclusive (writer) lock hold count,
320 * firstReader is the first thread to have acquired the read lock.
325 * read lock since then; null if there is no such thread.
353 * the read lock, and otherwise eligible to do so, should block
360 * the write lock, and otherwise eligible to do so, should block
390 * 3. Otherwise, this thread is eligible for lock if
403 throw new Error("Maximum lock count exceeded");
439 // Releasing the read lock has no effect on readers,
448 "attempt to unlock read lock, not locked by current thread");
454 * 1. If write lock held by another thread, fail.
456 * lock wrt state, so ask if it should block
511 // else we hold the exclusive lock; blocking here
514 // Make sure we're not acquiring read lock reentrantly
531 throw new Error("Maximum lock count exceeded");
566 throw new Error("Maximum lock count exceeded");
588 throw new Error("Maximum lock count exceeded");
657 * Reconstitute this lock instance from a stream
704 * The lock returned by method {@link ReentrantReadWriteLock#readLock}.
713 * @param lock the outer lock object
714 * @throws NullPointerException if the lock is null
716 protected ReadLock(ReentrantReadWriteLock lock) {
717 sync = lock.sync;
721 * Acquires the read lock.
723 * <p>Acquires the read lock if the write lock is not held by
726 * <p>If the write lock is held by another thread then
728 * purposes and lies dormant until the read lock has been acquired.
730 public void lock() {
735 * Acquires the read lock unless the current thread is
738 * <p>Acquires the read lock if the write lock is not held
741 * <p>If the write lock is held by another thread then the
747 * <li>The read lock is acquired by the current thread; or
761 * acquiring the read lock,
771 * lock.
780 * Acquires the read lock only if the write lock is not held by
783 * <p>Acquires the read lock if the write lock is not held by
785 * {@code true}. Even when this lock has been set to use a
787 * <em>will</em> immediately acquire the read lock if it is
789 * waiting for the read lock. This &quot;barging&quot; behavior
792 * for this lock, then use {@link #tryLock(long, TimeUnit)
796 * <p>If the write lock is held by another thread then
800 * @return {@code true} if the read lock was acquired
807 * Acquires the read lock if the write lock is not held by
812 * <p>Acquires the read lock if the write lock is not held by
814 * {@code true}. If this lock has been set to use a fair
815 * ordering policy then an available lock <em>will not</em> be
817 * lock. This is in contrast to the {@link #tryLock()}
819 * permit barging on a fair lock then combine the timed and
822 * <pre>if (lock.tryLock() || lock.tryLock(timeout, unit) ) { ... }
825 * <p>If the write lock is held by another thread then the
831 * <li>The read lock is acquired by the current thread; or
840 * <p>If the read lock is acquired then the value {@code true} is
850 * acquiring the read lock,
862 * lock, and over reporting the elapse of the waiting time.
864 * @param timeout the time to wait for the read lock
866 * @return {@code true} if the read lock was acquired
877 * Attempts to release this lock.
879 * <p> If the number of readers is now zero then the lock
880 * is made available for write lock attempts.
897 * Returns a string identifying this lock, as well as its lock state.
901 * @return a string identifying this lock, as well as its lock state
911 * The lock returned by method {@link ReentrantReadWriteLock#writeLock}.
920 * @param lock the outer lock object
921 * @throws NullPointerException if the lock is null
923 protected WriteLock(ReentrantReadWriteLock lock) {
924 sync = lock.sync;
928 * Acquires the write lock.
930 * <p>Acquires the write lock if neither the read nor write lock
932 * and returns immediately, setting the write lock hold count to
935 * <p>If the current thread already holds the write lock then the
939 * <p>If the lock is held by another thread then the current
941 * lies dormant until the write lock has been acquired, at which
942 * time the write lock hold count is set to one.
944 public void lock() {
949 * Acquires the write lock unless the current thread is
952 * <p>Acquires the write lock if neither the read nor write lock
954 * and returns immediately, setting the write lock hold count to
957 * <p>If the current thread already holds this lock then the
961 * <p>If the lock is held by another thread then the current
967 * <li>The write lock is acquired by the current thread; or
974 * <p>If the write lock is acquired by the current thread then the
975 * lock hold count is set to one.
985 * acquiring the write lock,
995 * lock.
1004 * Acquires the write lock only if it is not held by another thread
1007 * <p>Acquires the write lock if neither the read nor write lock
1010 * setting the write lock hold count to one. Even when this lock has
1013 * lock if it is available, whether or not other threads are
1014 * currently waiting for the write lock. This &quot;barging&quot;
1017 * fairness setting for this lock, then use {@link
1021 * <p> If the current thread already holds this lock then the
1025 * <p>If the lock is held by another thread then this method
1028 * @return {@code true} if the lock was free and was acquired
1029 * by the current thread, or the write lock was already held
1037 * Acquires the write lock if it is not held by another thread
1041 * <p>Acquires the write lock if neither the read nor write lock
1044 * setting the write lock hold count to one. If this lock has been
1045 * set to use a fair ordering policy then an available lock
1047 * waiting for the write lock. This is in contrast to the {@link
1049 * that does permit barging on a fair lock then combine the
1052 * <pre>if (lock.tryLock() || lock.tryLock(timeout, unit) ) { ... }
1055 * <p>If the current thread already holds this lock then the
1059 * <p>If the lock is held by another thread then the current
1065 * <li>The write lock is acquired by the current thread; or
1074 * <p>If the write lock is acquired then the value {@code true} is
1075 * returned and the write lock hold count is set to one.
1085 * acquiring the write lock,
1099 * lock, and over reporting the elapse of the waiting time.
1101 * @param timeout the time to wait for the write lock
1104 * @return {@code true} if the lock was free and was acquired
1105 * by the current thread, or the write lock was already held by the
1107 * elapsed before the lock could be acquired.
1119 * Attempts to release this lock.
1121 * <p>If the current thread is the holder of this lock then
1123 * zero then the lock is released. If the current thread is
1124 * not the holder of this lock then {@link
1128 * hold this lock.
1141 * monitor lock.
1145 * <li>If this write lock is not held when any {@link
1153 * lock.)
1156 * methods are called the write lock is released and, before
1157 * they return, the write lock is reacquired and the lock hold
1167 * <li>The ordering of lock reacquisition for threads returning
1169 * acquiring the lock, which is in the default case not specified,
1182 * Returns a string identifying this lock, as well as its lock
1187 * @return a string identifying this lock, as well as its lock state
1197 * Queries if this write lock is held by the current thread.
1201 * @return {@code true} if the current thread holds this lock and
1210 * Queries the number of holds on this write lock by the current
1211 * thread. A thread has a hold on a lock for each lock action
1215 * @return the number of holds on this lock by the current thread,
1216 * or zero if this lock is not held by the current thread
1227 * Returns {@code true} if this lock has fairness set true.
1229 * @return {@code true} if this lock has fairness set true
1236 * Returns the thread that currently owns the write lock, or
1239 * best-effort approximation of current lock status. For example,
1241 * threads trying to acquire the lock but have not yet done so.
1243 * subclasses that provide more extensive lock monitoring
1253 * Queries the number of read locks held for this lock. This
1263 * Queries if the write lock is held by any thread. This method is
1267 * @return {@code true} if any thread holds the write lock and
1275 * Queries if the write lock is held by the current thread.
1277 * @return {@code true} if the current thread holds the write lock and
1285 * Queries the number of reentrant write holds on this lock by the
1286 * current thread. A writer thread has a hold on a lock for
1287 * each lock action that is not matched by an unlock action.
1289 * @return the number of holds on the write lock by the current thread,
1290 * or zero if the write lock is not held by the current thread
1297 * Queries the number of reentrant read holds on this lock by the
1298 * current thread. A reader thread has a hold on a lock for
1299 * each lock action that is not matched by an unlock action.
1301 * @return the number of holds on the read lock by the current thread,
1302 * or zero if the read lock is not held by the current thread
1311 * acquire the write lock. Because the actual set of threads may
1316 * more extensive lock monitoring facilities.
1326 * acquire the read lock. Because the actual set of threads may
1331 * more extensive lock monitoring facilities.
1341 * write lock. Note that because cancellations may occur at any
1343 * thread will ever acquire a lock. This method is designed
1347 * acquire the lock
1355 * the read or write lock. Note that because cancellations may
1357 * that this thread will ever acquire a lock. This method is
1361 * @return {@code true} if the given thread is queued waiting for this lock
1370 * either the read or write lock. The value is only an estimate
1376 * @return the estimated number of threads waiting for this lock
1384 * acquire either the read or write lock. Because the actual set
1399 * associated with the write lock. Note that because timeouts and
1407 * @throws IllegalMonitorStateException if this lock is not held
1409 * not associated with this lock
1422 * given condition associated with the write lock. Note that because
1430 * @throws IllegalMonitorStateException if this lock is not held
1432 * not associated with this lock
1445 * waiting on the given condition associated with the write lock.
1455 * @throws IllegalMonitorStateException if this lock is not held
1457 * not associated with this lock
1469 * Returns a string identifying this lock, as well as its lock state.
1475 * @return a string identifying this lock, as well as its lock state