/** {@inheritDoc} */ @Override public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { int i = 0; long end = unit.toNanos(time) + System.nanoTime(); try { for (; i < locks.length && System.nanoTime() < end; i++) { if (!locks[i].writeLock().tryLock(time, unit)) break; } } finally { if (0 < i && i < locks.length) unlock0(i - 1); } return i == locks.length; }
/** * Internal lock routine. * * @param canInterrupt Whether to acquire the lock interruptibly. * @throws InterruptedException If interrupted. */ private void lock0(boolean canInterrupt) throws InterruptedException { int i = 0; try { for (; i < locks.length; i++) { if (canInterrupt) locks[i].writeLock().lockInterruptibly(); else locks[i].writeLock().lock(); } } catch (InterruptedException e) { unlock0(i - 1); throw e; } }
/** {@inheritDoc} */ @Override public boolean tryLock() { int i = 0; try { for (; i < locks.length; i++) { if (!locks[i].writeLock().tryLock()) break; } } finally { if (0 < i && i < locks.length) unlock0(i - 1); } return i == locks.length; }
/** * Internal lock routine. * * @param canInterrupt Whether to acquire the lock interruptibly. * @throws InterruptedException If interrupted. */ private void lock0(boolean canInterrupt) throws InterruptedException { int i = 0; try { for (; i < locks.length; i++) { if (canInterrupt) locks[i].writeLock().lockInterruptibly(); else locks[i].writeLock().lock(); } } catch (InterruptedException e) { unlock0(i - 1); throw e; } }
/** {@inheritDoc} */ @SuppressWarnings("NullableProblems") @Override public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { int i = 0; long end = unit.toNanos(time) + System.nanoTime(); try { for (; i < locks.length && System.nanoTime() < end; i++) { if (!locks[i].writeLock().tryLock(time, unit)) break; } } finally { if (0 < i && i < locks.length) unlock0(i - 1); } return i == locks.length; }
/** {@inheritDoc} */ @Override public boolean tryLock() { int i = 0; try { for (; i < locks.length; i++) { if (!locks[i].writeLock().tryLock()) break; } } finally { if (0 < i && i < locks.length) unlock0(i - 1); } return i == locks.length; }
/** {@inheritDoc} */ @Override public void unlock() { unlock0(locks.length - 1); }
/** {@inheritDoc} */ @Override public void unlock() { unlock0(locks.length - 1); }