ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java (file contents):
Revision 1.1 by dl, Sun Dec 28 21:56:18 2003 UTC vs.
Revision 1.7 by dl, Fri Jan 2 21:06:38 2004 UTC

# Line 30 | Line 30 | public class AbstractQueuedSynchronizerT
30       */
31      static class Mutex implements Lock, java.io.Serializable {
32          private static class Sync extends AbstractQueuedSynchronizer {
33 <            public int acquireExclusiveState(boolean isQueued, int acquires, Thread current) {
33 >            boolean isLocked() { return getState() == 1; }
34 >
35 >            public boolean tryAcquireExclusive(boolean isQueued, int acquires) {
36                  assert acquires == 1; // Does not use multiple acquires
37 <                return state().compareAndSet(0, 1)? 0 : -1;
37 >                return compareAndSetState(0, 1);
38              }
39              
40 <            public boolean releaseExclusiveState(int releases) {
41 <                state().set(0);
40 >            public boolean tryReleaseExclusive(int releases) {
41 >                setState(0);
42                  return true;
43              }
44              
43            public int acquireSharedState(boolean isQueued, int acquires, Thread current) {
44                throw new UnsupportedOperationException();
45            }
46            
47            public boolean releaseSharedState(int releases) {
48                throw new UnsupportedOperationException();
49            }
50            
45              public void checkConditionAccess(Thread thread, boolean waiting) {
46 <                if (state().get() == 0) throw new IllegalMonitorStateException();
46 >                if (getState() == 0) throw new IllegalMonitorStateException();
47              }
48              
49              Condition newCondition() { return new ConditionObject(); }
50              
51              private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
52                  s.defaultReadObject();
53 <                state().set(0); // reset to unlocked state
53 >                setState(0); // reset to unlocked state
54              }
55          }
56 <        
56 >        
57          private final Sync sync = new Sync();
64        public void lock() { sync.acquireExclusiveUninterruptibly(1);  }
58          public boolean tryLock() {
59 <            return sync.acquireExclusiveState(false, 1, null) >= 0;
59 >            return sync.tryAcquireExclusive(false, 1);
60 >        }
61 >        public void lock() {
62 >            sync.acquireExclusiveUninterruptibly(1);
63          }
64          public void lockInterruptibly() throws InterruptedException {
65              sync.acquireExclusiveInterruptibly(1);
# Line 73 | Line 69 | public class AbstractQueuedSynchronizerT
69          }
70          public void unlock() { sync.releaseExclusive(1); }
71          public Condition newCondition() { return sync.newCondition(); }
72 <        public boolean isLocked() { return sync.state().get() != 0; }
72 >        public boolean isLocked() { return sync.isLocked(); }
73          public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); }
74      }
75  
# Line 117 | Line 113 | public class AbstractQueuedSynchronizerT
113      }
114  
115      /**
116 <     * trylock on an unlocked lock succeeds
116 >     * tryLock on an unlocked lock succeeds
117       */
118      public void testTryLock() {
119          Mutex rl = new Mutex();
# Line 156 | Line 152 | public class AbstractQueuedSynchronizerT
152      }
153  
154      /**
155 <     * timed trylock is interruptible.
155 >     * timed tryLock is interruptible.
156       */
157      public void testInterruptedException2() {
158          final Mutex lock = new Mutex();
# Line 179 | Line 175 | public class AbstractQueuedSynchronizerT
175  
176  
177      /**
178 <     * Trylock on a locked lock fails
178 >     * TryLock on a locked lock fails
179       */
180      public void testTryLockWhenLocked() {
181          final Mutex lock = new Mutex();
# Line 199 | Line 195 | public class AbstractQueuedSynchronizerT
195      }
196  
197      /**
198 <     * Timed trylock on a locked lock times out
198 >     * Timed tryLock on a locked lock times out
199       */
200      public void testTryLock_Timeout() {
201          final Mutex lock = new Mutex();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines