/************************************************* * * = PACKAGE * JACE.Concurrency * * = FILENAME * Mutex.java * *@author Prashant Jain * *************************************************/ package JACE.Concurrency; import java.util.*; import JACE.ASX.*; class TimedWaitMAdapter extends TimedWait { TimedWaitMAdapter (Object obj) { super (obj); } // Check to see if the lock is currently held or not. public boolean condition () { return !this.inUse_; } // Acquire/Release the lock public void inUse (boolean c) { this.inUse_ = c; } private boolean inUse_ = false; // The actual lock } /** *
* Value added abstraction for mutex variable creation. ** *
* A timed mutex, i.e. a mutex whose operations do not * block forever and can*/ public class Mutex { /** * Acquire the mutex. Note that this will block. *@exception InterruptedException exception during wait */ public synchronized void acquire () throws InterruptedException { this.monitor_.timedWait (); this.monitor_.inUse (true); } /** * Acquire the mutex. Note that the call will return iftime out. *