< prev index next >

src/java.corba/share/classes/com/sun/corba/se/impl/orbutil/concurrent/Mutex.java

Print this page




 109  *              throw ex;
 110  *            }
 111  *            p.lock.release();      // release old lock now that new one held
 112  *            p = nextp;
 113  *          }
 114  *        }
 115  *      }
 116  *    }
 117  *
 118  *    synchronized void add(Object x) { // simple prepend
 119  *      // The use of `synchronized'  here protects only head field.
 120  *      // The method does not need to wait out other traversers
 121  *      // who have already made it past head.
 122  *
 123  *      head = new Node(x, head);
 124  *    }
 125  *
 126  *    // ...  other similar traversal and update methods ...
 127  * }
 128  * </pre>
 129  * <p>
 130  * @see Semaphore
 131  * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
 132 **/
 133 
 134 public class Mutex implements Sync  {
 135 
 136   /** The lock status **/
 137   protected boolean inuse_ = false;
 138 
 139   public void acquire() throws InterruptedException {
 140     if (Thread.interrupted()) throw new InterruptedException();
 141     synchronized(this) {
 142       try {
 143         while (inuse_) wait();
 144         inuse_ = true;
 145       }
 146       catch (InterruptedException ex) {
 147         notify();
 148         throw ex;
 149       }




 109  *              throw ex;
 110  *            }
 111  *            p.lock.release();      // release old lock now that new one held
 112  *            p = nextp;
 113  *          }
 114  *        }
 115  *      }
 116  *    }
 117  *
 118  *    synchronized void add(Object x) { // simple prepend
 119  *      // The use of `synchronized'  here protects only head field.
 120  *      // The method does not need to wait out other traversers
 121  *      // who have already made it past head.
 122  *
 123  *      head = new Node(x, head);
 124  *    }
 125  *
 126  *    // ...  other similar traversal and update methods ...
 127  * }
 128  * </pre>

 129  * @see Semaphore
 130  * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
 131 **/
 132 
 133 public class Mutex implements Sync  {
 134 
 135   /** The lock status **/
 136   protected boolean inuse_ = false;
 137 
 138   public void acquire() throws InterruptedException {
 139     if (Thread.interrupted()) throw new InterruptedException();
 140     synchronized(this) {
 141       try {
 142         while (inuse_) wait();
 143         inuse_ = true;
 144       }
 145       catch (InterruptedException ex) {
 146         notify();
 147         throw ex;
 148       }


< prev index next >