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

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

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

revision 1.41, Mon Jul 17 21:01:30 2017 UTC revision 1.42, Fri Sep 29 19:34:37 2017 UTC
# Line 31  Line 31 
31      /**      /**
32       * A simple mutex class, adapted from the class javadoc.  Exclusive       * A simple mutex class, adapted from the class javadoc.  Exclusive
33       * acquire tests exercise this as a sample user extension.       * acquire tests exercise this as a sample user extension.
34         *
35         * Unlike the javadoc sample, we don't track owner thread via
36         * AbstractOwnableSynchronizer methods.
37       */       */
38      static class Mutex extends AbstractQueuedLongSynchronizer {      static class Mutex extends AbstractQueuedLongSynchronizer {
39          /** An eccentric value > 32 bits for locked synchronizer state. */          /** An eccentric value > 32 bits for locked synchronizer state. */
# Line 38  Line 41 
41    
42          static final long UNLOCKED = 0;          static final long UNLOCKED = 0;
43    
44          public boolean isHeldExclusively() {          /** Owner thread is untracked, so this is really just isLocked(). */
45            @Override public boolean isHeldExclusively() {
46              long state = getState();              long state = getState();
47              assertTrue(state == UNLOCKED || state == LOCKED);              assertTrue(state == UNLOCKED || state == LOCKED);
48              return state == LOCKED;              return state == LOCKED;
49          }          }
50    
51          public boolean tryAcquire(long acquires) {          @Override protected boolean tryAcquire(long acquires) {
52              assertEquals(LOCKED, acquires);              assertEquals(LOCKED, acquires);
53              return compareAndSetState(UNLOCKED, LOCKED);              return compareAndSetState(UNLOCKED, LOCKED);
54          }          }
55    
56          public boolean tryRelease(long releases) {          @Override protected boolean tryRelease(long releases) {
57              if (getState() != LOCKED) throw new IllegalMonitorStateException();              if (getState() != LOCKED) throw new IllegalMonitorStateException();
58              setState(UNLOCKED);              setState(UNLOCKED);
59              return true;              return true;
# Line 79  Line 83 
83              release(LOCKED);              release(LOCKED);
84          }          }
85    
86            /** Faux-Implements Lock.newCondition(). */
87          public ConditionObject newCondition() {          public ConditionObject newCondition() {
88              return new ConditionObject();              return new ConditionObject();
89          }          }
90      }      }
91    
92      /**      /**
93       * A simple latch class, to test shared mode.       * A minimal latch class, to test shared mode.
94       */       */
95      static class BooleanLatch extends AbstractQueuedLongSynchronizer {      static class BooleanLatch extends AbstractQueuedLongSynchronizer {
96          public boolean isSignalled() { return getState() != 0; }          public boolean isSignalled() { return getState() != 0; }

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.42

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8