[cvs] / jsr166 / src / test / tck / AbstractQueuedSynchronizerTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5, Tue Dec 30 15:48:38 2003 UTC revision 1.6, Wed Dec 31 21:30:08 2003 UTC
# Line 30  Line 30 
30       */       */
31      static class Mutex implements Lock, java.io.Serializable {      static class Mutex implements Lock, java.io.Serializable {
32          private static class Sync extends AbstractQueuedSynchronizer {          private static class Sync extends AbstractQueuedSynchronizer {
33              public int acquireExclusiveState(boolean isQueued, int acquires) {              boolean isLocked() { return getState() == 1; }
34    
35                public boolean tryAcquireExclusiveState(boolean isQueued, int acquires) {
36                  assert acquires == 1; // Does not use multiple acquires                  assert acquires == 1; // Does not use multiple acquires
37                  return compareAndSet(0, 1)? 0 : -1;                  return compareAndSetState(0, 1);
38              }              }
39    
40              public boolean releaseExclusiveState(int releases) {              public boolean releaseExclusiveState(int releases) {
41                  set(0);                  setState(0);
42                  return true;                  return true;
43              }              }
44    
45              public void checkConditionAccess(Thread thread, boolean waiting) {              public void checkConditionAccess(Thread thread, boolean waiting) {
46                  if (get() == 0) throw new IllegalMonitorStateException();                  if (getState() == 0) throw new IllegalMonitorStateException();
47              }              }
48    
49              Condition newCondition() { return new ConditionObject(); }              Condition newCondition() { return new ConditionObject(); }
50    
51              private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {              private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
52                  s.defaultReadObject();                  s.defaultReadObject();
53                  set(0); // reset to unlocked state                  setState(0); // reset to unlocked state
54              }              }
55          }          }
56    
57          private final Sync sync = new Sync();          private final Sync sync = new Sync();
58          public boolean tryLock() {          public boolean tryLock() {
59              return sync.acquireExclusiveState(false, 1) >= 0;              return sync.tryAcquireExclusiveState(false, 1);
60          }          }
61          public void lock() {          public void lock() {
62              sync.acquireExclusiveUninterruptibly(1);              sync.acquireExclusiveUninterruptibly(1);
# Line 67  Line 69 
69          }          }
70          public void unlock() { sync.releaseExclusive(1); }          public void unlock() { sync.releaseExclusive(1); }
71          public Condition newCondition() { return sync.newCondition(); }          public Condition newCondition() { return sync.newCondition(); }
72          public boolean isLocked() { return sync.get() != 0; }          public boolean isLocked() { return sync.isLocked(); }
73          public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); }          public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); }
74      }      }
75    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8