&& shouldParkAfterFailedAcquire(p, node)) LockSupport.parkNanos(nanosTimeout); long now = System.nanoTime();
&& shouldParkAfterFailedAcquire(p, node)) LockSupport.parkNanos(nanosTimeout); long now = System.nanoTime();
/** * Acquires in exclusive interruptible mode. * * @param arg * the acquire argument */ private void doAcquireInterruptibly(int arg, Object id) throws InterruptedException { final Node node = addWaiter(Node.EXCLUSIVE); try { for (;;) { final Node p = node.predecessor(); if (p == head && tryAcquire(arg, id)) { setHead(node); p.next = null; // help GC return; } if (shouldParkAfterFailedAcquire(p, node) && parkAndCheckInterrupt()) break; } } catch (RuntimeException ex) { cancelAcquire(node); throw ex; } // Arrive here only if interrupted cancelAcquire(node); throw new InterruptedException(); }
/** * Acquires in exclusive uninterruptible mode for thread already in queue. * Used by condition wait methods as well as acquire. * * @param node * the node * @param arg * the acquire argument * @return {@code true} if interrupted while waiting */ final boolean acquireQueued(final Node node, int arg, Object id) { try { boolean interrupted = false; for (;;) { final Node p = node.predecessor(); if (p == head && tryAcquire(arg, id)) { setHead(node); p.next = null; // help GC return interrupted; } if (shouldParkAfterFailedAcquire(p, node) && parkAndCheckInterrupt()) interrupted = true; } } catch (RuntimeException ex) { cancelAcquire(node); throw ex; } }
if (shouldParkAfterFailedAcquire(p, node) && parkAndCheckInterrupt()) break;
/** * Acquires in shared uninterruptible mode. * * @param arg * the acquire argument */ private void doAcquireShared(int arg, Object id) { final Node node = addWaiter(Node.SHARED); try { boolean interrupted = false; for (;;) { final Node p = node.predecessor(); if (p == head) { int r = tryAcquireShared(arg, id); if (r >= 0) { setHeadAndPropagate(node, r); p.next = null; // help GC if (interrupted) selfInterrupt(); return; } } if (shouldParkAfterFailedAcquire(p, node) && parkAndCheckInterrupt()) interrupted = true; } } catch (RuntimeException ex) { cancelAcquire(node); throw ex; } }