home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / awt / Mutex.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  638 b   |  40 lines

  1. package sun.awt;
  2.  
  3. public class Mutex {
  4.    private boolean locked;
  5.    private Thread owner;
  6.  
  7.    public synchronized void lock() {
  8.       if (this.locked && Thread.currentThread() == this.owner) {
  9.          throw new IllegalMonitorStateException();
  10.       } else {
  11.          do {
  12.             if (!this.locked) {
  13.                this.locked = true;
  14.                this.owner = Thread.currentThread();
  15.             } else {
  16.                try {
  17.                   this.wait();
  18.                } catch (InterruptedException var2) {
  19.                }
  20.             }
  21.          } while(this.owner != Thread.currentThread());
  22.  
  23.       }
  24.    }
  25.  
  26.    public synchronized void unlock() {
  27.       if (Thread.currentThread() != this.owner) {
  28.          throw new IllegalMonitorStateException();
  29.       } else {
  30.          this.owner = null;
  31.          this.locked = false;
  32.          this.notify();
  33.       }
  34.    }
  35.  
  36.    protected boolean isOwned() {
  37.       return this.locked && Thread.currentThread() == this.owner;
  38.    }
  39. }
  40.