コード例 #1
0
 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
   }
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 public synchronized void takeOver(WaitQueue.WaitNode node) {
   // assert (holds_ == 1 && owner_ == Thread.currentThread()
   owner_ = node.getOwner();
 }