home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / sun / awt / Mutex.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  578 b   |  36 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.