195 * double currentX = x;
196 * double currentY = y;
197 * if (!sl.validate(stamp))
198 * continue retryHoldingLock;
199 * if (currentX != 0.0 || currentY != 0.0)
200 * break;
201 * stamp = sl.tryConvertToWriteLock(stamp);
202 * if (stamp == 0L)
203 * continue retryHoldingLock;
204 * // exclusive access
205 * x = newX;
206 * y = newY;
207 * return;
208 * }
209 * } finally {
210 * if (StampedLock.isWriteLockStamp(stamp))
211 * sl.unlockWrite(stamp);
212 * }
213 * }
214 *
215 * // Upgrade read lock to write lock
216 * void moveIfAtOrigin(double newX, double newY) {
217 * long stamp = sl.readLock();
218 * try {
219 * while (x == 0.0 && y == 0.0) {
220 * long ws = sl.tryConvertToWriteLock(stamp);
221 * if (ws != 0L) {
222 * stamp = ws;
223 * x = newX;
224 * y = newY;
225 * break;
226 * }
227 * else {
228 * sl.unlockRead(stamp);
229 * stamp = sl.writeLock();
230 * }
231 * }
232 * } finally {
233 * sl.unlock(stamp);
234 * }
235 * }
236 * }}</pre>
|
195 * double currentX = x;
196 * double currentY = y;
197 * if (!sl.validate(stamp))
198 * continue retryHoldingLock;
199 * if (currentX != 0.0 || currentY != 0.0)
200 * break;
201 * stamp = sl.tryConvertToWriteLock(stamp);
202 * if (stamp == 0L)
203 * continue retryHoldingLock;
204 * // exclusive access
205 * x = newX;
206 * y = newY;
207 * return;
208 * }
209 * } finally {
210 * if (StampedLock.isWriteLockStamp(stamp))
211 * sl.unlockWrite(stamp);
212 * }
213 * }
214 *
215 * // upgrade read lock to write lock
216 * void moveIfAtOrigin2(double newX, double newY) {
217 * long stamp = sl.readLock();
218 * try {
219 * while (x == 0.0 && y == 0.0) {
220 * long ws = sl.tryConvertToWriteLock(stamp);
221 * if (ws != 0L) {
222 * stamp = ws;
223 * x = newX;
224 * y = newY;
225 * break;
226 * }
227 * else {
228 * sl.unlockRead(stamp);
229 * stamp = sl.writeLock();
230 * }
231 * }
232 * } finally {
233 * sl.unlock(stamp);
234 * }
235 * }
236 * }}</pre>
|