[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.57, Mon Jul 17 21:01:30 2017 UTC revision 1.58, Fri Sep 29 19:34:37 2017 UTC
# Line 34  Line 34 
34       * methods/features of AbstractQueuedSynchronizer are tested via       * methods/features of AbstractQueuedSynchronizer are tested via
35       * other test classes, including those for ReentrantLock,       * other test classes, including those for ReentrantLock,
36       * ReentrantReadWriteLock, and Semaphore.       * ReentrantReadWriteLock, and Semaphore.
37         *
38         * Unlike the javadoc sample, we don't track owner thread via
39         * AbstractOwnableSynchronizer methods.
40       */       */
41      static class Mutex extends AbstractQueuedSynchronizer {      static class Mutex extends AbstractQueuedSynchronizer {
42          /** An eccentric value for locked synchronizer state. */          /** An eccentric value for locked synchronizer state. */
# Line 41  Line 44 
44    
45          static final int UNLOCKED = 0;          static final int UNLOCKED = 0;
46    
47            /** Owner thread is untracked, so this is really just isLocked(). */
48          @Override public boolean isHeldExclusively() {          @Override public boolean isHeldExclusively() {
49              int state = getState();              int state = getState();
50              assertTrue(state == UNLOCKED || state == LOCKED);              assertTrue(state == UNLOCKED || state == LOCKED);
51              return state == LOCKED;              return state == LOCKED;
52          }          }
53    
54          @Override public boolean tryAcquire(int acquires) {          @Override protected boolean tryAcquire(int acquires) {
55              assertEquals(LOCKED, acquires);              assertEquals(LOCKED, acquires);
56              return compareAndSetState(UNLOCKED, LOCKED);              return compareAndSetState(UNLOCKED, LOCKED);
57          }          }
58    
59          @Override public boolean tryRelease(int releases) {          @Override protected boolean tryRelease(int releases) {
60              if (getState() != LOCKED) throw new IllegalMonitorStateException();              if (getState() != LOCKED) throw new IllegalMonitorStateException();
61              assertEquals(LOCKED, releases);              assertEquals(LOCKED, releases);
62              setState(UNLOCKED);              setState(UNLOCKED);
# Line 83  Line 87 
87              release(LOCKED);              release(LOCKED);
88          }          }
89    
90            /** Faux-Implements Lock.newCondition(). */
91          public ConditionObject newCondition() {          public ConditionObject newCondition() {
92              return new ConditionObject();              return new ConditionObject();
93          }          }
94      }      }
95    
96      /**      /**
97       * A simple latch class, to test shared mode.       * A minimal latch class, to test shared mode.
98       */       */
99      static class BooleanLatch extends AbstractQueuedSynchronizer {      static class BooleanLatch extends AbstractQueuedSynchronizer {
100          public boolean isSignalled() { return getState() != 0; }          public boolean isSignalled() { return getState() != 0; }

Legend:
Removed from v.1.57  
changed lines
  Added in v.1.58

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8