View Javadoc
1   package locklib.mutex;
2   
3   import locklib.LockPolicy;
4   import ensure.Ensure;
5   
6   /**
7    * Locking policy for mutex locking. In a mutex locking policy, locking a
8    * child requires locking its parent.
9    */
10  public class MutexLockPolicy implements LockPolicy<MutexLockType> {
11  	/**
12  	 * Creates a new mutex locking policy.
13  	 */
14  	public MutexLockPolicy() {
15  	}
16  
17  	@Override
18  	public boolean is_compatible(MutexLockType lock_type_1,
19  			MutexLockType lock_type_2) {
20  		Ensure.not_null(lock_type_1, "lock_type_1 == null");
21  		Ensure.not_null(lock_type_2, "lock_type_2 == null");
22  		
23  		return false;
24  	}
25  
26  	@Override
27  	public MutexLockType parent_lock(MutexLockType lock_type) {
28  		Ensure.not_null(lock_type, "lock_type == null");
29  		
30  		return lock_type;
31  	}
32  	
33  	@Override
34  	public boolean starvation_allowed() {
35  		return false;
36  	}
37  }