public void lockInterruptibly() throws InterruptedException {
   if (Thread.interrupted()) throw new InterruptedException();
   Thread caller = Thread.currentThread();
   synchronized (this) {
     if (owner_ == null) {
       owner_ = caller;
       holds_ = 1;
       return;
     } else if (caller == owner_) {
       incHolds();
       return;
     } else {
       try {
         do {
           wait();
         } while (owner_ != null);
         owner_ = caller;
         holds_ = 1;
         return;
       } catch (InterruptedException ex) {
         if (owner_ == null) notify();
         throw ex;
       }
     }
   }
 }
 public void lock() {
   Thread caller = Thread.currentThread();
   synchronized (this) {
     if (owner_ == null) {
       owner_ = caller;
       holds_ = 1;
       return;
     } else if (caller == owner_) {
       incHolds();
       return;
     } else {
       boolean wasInterrupted = Thread.interrupted();
       try {
         while (true) {
           try {
             wait();
           } catch (InterruptedException e) {
             wasInterrupted = true;
             // no need to notify; if we were signalled, we
             // will act as signalled, ignoring the
             // interruption
           }
           if (owner_ == null) {
             owner_ = caller;
             holds_ = 1;
             return;
           }
         }
       } finally {
         if (wasInterrupted) Thread.currentThread().interrupt();
       }
     }
   }
 }
 public boolean tryLock(long nanos) throws InterruptedException {
   if (Thread.interrupted()) throw new InterruptedException();
   Thread caller = Thread.currentThread();
   synchronized (this) {
     if (owner_ == null) {
       owner_ = caller;
       holds_ = 1;
       return true;
     } else if (caller == owner_) {
       incHolds();
       return true;
     }
   }
   WaitQueue.WaitNode n = new WaitQueue.WaitNode();
   return n.doTimedWait(this, nanos);
 }
 public void lockInterruptibly() throws InterruptedException {
   if (Thread.interrupted()) throw new InterruptedException();
   Thread caller = Thread.currentThread();
   synchronized (this) {
     if (owner_ == null) {
       owner_ = caller;
       holds_ = 1;
       return;
     } else if (caller == owner_) {
       incHolds();
       return;
     }
   }
   WaitQueue.WaitNode n = new WaitQueue.WaitNode();
   n.doWait(this);
 }
 public void unlock() {
   Thread caller = Thread.currentThread();
   for (; ; ) {
     WaitQueue.WaitNode w = getSignallee(caller);
     if (w == null) return; // no one to signal
     if (w.signal(this)) return; // notify if still waiting, else skip
   }
 }
    public synchronized void unlock() {
      if (Thread.currentThread() != owner_) throw new IllegalMonitorStateException("Not owner");

      if (--holds_ == 0) {
        owner_ = null;
        notify();
      }
    }
 public synchronized boolean recheck(WaitQueue.WaitNode node) {
   Thread caller = Thread.currentThread();
   if (owner_ == null) {
     owner_ = caller;
     holds_ = 1;
     return true;
   } else if (caller == owner_) {
     incHolds();
     return true;
   }
   wq_.insert(node);
   return false;
 }
 public boolean tryLock() {
   Thread caller = Thread.currentThread();
   synchronized (this) {
     if (owner_ == null) {
       owner_ = caller;
       holds_ = 1;
       return true;
     } else if (caller == owner_) {
       incHolds();
       return true;
     }
   }
   return false;
 }
    public boolean tryLock(long nanos) throws InterruptedException {
      if (Thread.interrupted()) throw new InterruptedException();
      Thread caller = Thread.currentThread();

      synchronized (this) {
        if (owner_ == null) {
          owner_ = caller;
          holds_ = 1;
          return true;
        } else if (caller == owner_) {
          incHolds();
          return true;
        } else if (nanos <= 0) return false;
        else {
          long deadline = Utils.nanoTime() + nanos;
          try {
            for (; ; ) {
              TimeUnit.NANOSECONDS.timedWait(this, nanos);
              if (caller == owner_) {
                incHolds();
                return true;
              } else if (owner_ == null) {
                owner_ = caller;
                holds_ = 1;
                return true;
              } else {
                nanos = deadline - Utils.nanoTime();
                if (nanos <= 0) return false;
              }
            }
          } catch (InterruptedException ex) {
            if (owner_ == null) notify();
            throw ex;
          }
        }
      }
    }
 public void lock() {
   Thread caller = Thread.currentThread();
   synchronized (this) {
     if (owner_ == null) {
       owner_ = caller;
       holds_ = 1;
       return;
     } else if (caller == owner_) {
       incHolds();
       return;
     }
   }
   WaitQueue.WaitNode n = new WaitQueue.WaitNode();
   n.doWaitUninterruptibly(this);
 }
 /**
  * Returns a string identifying this lock, as well as its lock state. The state, in brackets,
  * includes either the String &quot;Unlocked&quot; or the String &quot;Locked by&quot; followed by
  * the {@link Thread#getName} of the owning thread.
  *
  * @return a string identifying this lock, as well as its lock state.
  */
 public String toString() {
   Thread o = getOwner();
   return super.toString()
       + ((o == null) ? "[Unlocked]" : "[Locked by thread " + o.getName() + "]");
 }
 public synchronized boolean isHeldByCurrentThread() {
   return holds_ > 0 && Thread.currentThread() == owner_;
 }