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.15 by dl, Sat Jan 10 20:37:20 2004 UTC vs.
Revision 1.16 by dl, Sun Jan 11 16:02:33 2004 UTC

# Line 30 | Line 30 | public class AbstractQueuedSynchronizerT
30       * ReentrantReadWriteLock, and Semaphore
31       */
32      static class Mutex extends AbstractQueuedSynchronizer {
33 <        public boolean isLocked() { return getState() == 1; }
33 >        public boolean isHeldExclusively() { return getState() == 1; }
34          
35 <        public boolean tryAcquireExclusive(int acquires) {
35 >        public boolean tryAcquire(int acquires) {
36              assertTrue(acquires == 1);
37              return compareAndSetState(0, 1);
38          }
39          
40 <        public boolean tryReleaseExclusive(int releases) {
40 >        public boolean tryRelease(int releases) {
41 >            if (getState() == 0) throw new IllegalMonitorStateException();
42              setState(0);
43              return true;
44          }
45          
45        public void checkConditionAccess(Thread thread) {
46            if (getState() == 0) throw new IllegalMonitorStateException();
47        }
48        
46          public AbstractQueuedSynchronizer.ConditionObject newCondition() { return new AbstractQueuedSynchronizer.ConditionObject(); }
47          
48          public void lock() {
49 <            acquireExclusiveUninterruptibly(1);
49 >            acquire(1);
50          }
51  
52      }
# Line 72 | Line 69 | public class AbstractQueuedSynchronizerT
69      }
70  
71      /**
72 <     * A runnable calling acquireExclusiveInterruptibly
72 >     * A runnable calling acquireInterruptibly
73       */
74      class InterruptibleLockRunnable implements Runnable {
75          final Mutex lock;
76          InterruptibleLockRunnable(Mutex l) { lock = l; }
77          public void run() {
78              try {
79 <                lock.acquireExclusiveInterruptibly(1);
79 >                lock.acquireInterruptibly(1);
80              } catch(InterruptedException success){}
81          }
82      }
83  
84  
85      /**
86 <     * A runnable calling acquireExclusiveInterruptibly that expects to be
86 >     * A runnable calling acquireInterruptibly that expects to be
87       * interrupted
88       */
89      class InterruptedLockRunnable implements Runnable {
# Line 94 | Line 91 | public class AbstractQueuedSynchronizerT
91          InterruptedLockRunnable(Mutex l) { lock = l; }
92          public void run() {
93              try {
94 <                lock.acquireExclusiveInterruptibly(1);
94 >                lock.acquireInterruptibly(1);
95                  threadShouldThrow();
96              } catch(InterruptedException success){}
97          }
98      }
99 +
100 +    /**
101 +     * isHeldExclusively is false upon construction
102 +     */
103 +    public void testIsHeldExclusively() {
104 +        Mutex rl = new Mutex();
105 +        assertFalse(rl.isHeldExclusively());
106 +    }
107      
108      /**
109 <     * acquireExclusiveUninterruptiblying an releaseExclusiveed lock succeeds
109 >     * acquiring released lock succeeds
110       */
111 <    public void testAcquireExclusiveUninterruptibly() {
111 >    public void testAcquire() {
112          Mutex rl = new Mutex();
113 <        rl.acquireExclusiveUninterruptibly(1);
114 <        assertTrue(rl.isLocked());
115 <        rl.releaseExclusive(1);
113 >        rl.acquire(1);
114 >        assertTrue(rl.isHeldExclusively());
115 >        rl.release(1);
116      }
117  
118      /**
119 <     * tryAcquireExclusive on an releaseExclusiveed lock succeeds
119 >     * tryAcquire on an released lock succeeds
120       */
121 <    public void testTryAcquireExclusive() {
121 >    public void testTryAcquire() {
122          Mutex rl = new Mutex();
123 <        assertTrue(rl.tryAcquireExclusive(1));
124 <        assertTrue(rl.isLocked());
125 <        rl.releaseExclusive(1);
123 >        assertTrue(rl.tryAcquire(1));
124 >        assertTrue(rl.isHeldExclusively());
125 >        rl.release(1);
126      }
127  
128      /**
# Line 129 | Line 134 | public class AbstractQueuedSynchronizerT
134          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
135          try {
136              assertFalse(lock.hasQueuedThreads());
137 <            lock.acquireExclusiveUninterruptibly(1);
137 >            lock.acquire(1);
138              t1.start();
139              Thread.sleep(SHORT_DELAY_MS);
140              assertTrue(lock.hasQueuedThreads());
# Line 139 | Line 144 | public class AbstractQueuedSynchronizerT
144              t1.interrupt();
145              Thread.sleep(SHORT_DELAY_MS);
146              assertTrue(lock.hasQueuedThreads());
147 <            lock.releaseExclusive(1);
147 >            lock.release(1);
148              Thread.sleep(SHORT_DELAY_MS);
149              assertFalse(lock.hasQueuedThreads());
150              t1.join();
# Line 171 | Line 176 | public class AbstractQueuedSynchronizerT
176          try {
177              assertFalse(lock.isQueued(t1));
178              assertFalse(lock.isQueued(t2));
179 <            lock.acquireExclusiveUninterruptibly(1);
179 >            lock.acquire(1);
180              t1.start();
181              Thread.sleep(SHORT_DELAY_MS);
182              assertTrue(lock.isQueued(t1));
# Line 183 | Line 188 | public class AbstractQueuedSynchronizerT
188              Thread.sleep(SHORT_DELAY_MS);
189              assertFalse(lock.isQueued(t1));
190              assertTrue(lock.isQueued(t2));
191 <            lock.releaseExclusive(1);
191 >            lock.release(1);
192              Thread.sleep(SHORT_DELAY_MS);
193              assertFalse(lock.isQueued(t1));
194              assertFalse(lock.isQueued(t2));
# Line 203 | Line 208 | public class AbstractQueuedSynchronizerT
208          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
209          try {
210              assertNull(lock.getFirstQueuedThread());
211 <            lock.acquireExclusiveUninterruptibly(1);
211 >            lock.acquire(1);
212              t1.start();
213              Thread.sleep(SHORT_DELAY_MS);
214              assertEquals(t1, lock.getFirstQueuedThread());
# Line 213 | Line 218 | public class AbstractQueuedSynchronizerT
218              t1.interrupt();
219              Thread.sleep(SHORT_DELAY_MS);
220              assertEquals(t2, lock.getFirstQueuedThread());
221 <            lock.releaseExclusive(1);
221 >            lock.release(1);
222              Thread.sleep(SHORT_DELAY_MS);
223              assertNull(lock.getFirstQueuedThread());
224              t1.join();
# Line 233 | Line 238 | public class AbstractQueuedSynchronizerT
238          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
239          try {
240              assertFalse(lock.hasContended());
241 <            lock.acquireExclusiveUninterruptibly(1);
241 >            lock.acquire(1);
242              t1.start();
243              Thread.sleep(SHORT_DELAY_MS);
244              assertTrue(lock.hasContended());
# Line 243 | Line 248 | public class AbstractQueuedSynchronizerT
248              t1.interrupt();
249              Thread.sleep(SHORT_DELAY_MS);
250              assertTrue(lock.hasContended());
251 <            lock.releaseExclusive(1);
251 >            lock.release(1);
252              Thread.sleep(SHORT_DELAY_MS);
253              assertTrue(lock.hasContended());
254              t1.join();
# Line 254 | Line 259 | public class AbstractQueuedSynchronizerT
259      }
260  
261      /**
262 <     * acquireExclusiveNanos is interruptible.
262 >     * tryAcquireNanos is interruptible.
263       */
264      public void testInterruptedException2() {
265          final Mutex lock = new Mutex();
266 <        lock.acquireExclusiveUninterruptibly(1);
266 >        lock.acquire(1);
267          Thread t = new Thread(new Runnable() {
268                  public void run() {
269                      try {
270 <                        lock.acquireExclusiveNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
270 >                        lock.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
271                          threadShouldThrow();
272                      } catch(InterruptedException success){}
273                  }
# Line 277 | Line 282 | public class AbstractQueuedSynchronizerT
282  
283  
284      /**
285 <     * TryAcquireExclusive on a locked lock fails
285 >     * TryAcquire on a locked lock fails
286       */
287 <    public void testTryAcquireExclusiveWhenLocked() {
287 >    public void testTryAcquireWhenLocked() {
288          final Mutex lock = new Mutex();
289 <        lock.acquireExclusiveUninterruptibly(1);
289 >        lock.acquire(1);
290          Thread t = new Thread(new Runnable() {
291                  public void run() {
292 <                    threadAssertFalse(lock.tryAcquireExclusive(1));
292 >                    threadAssertFalse(lock.tryAcquire(1));
293                  }
294              });
295          try {
296              t.start();
297              t.join();
298 <            lock.releaseExclusive(1);
298 >            lock.release(1);
299          } catch(Exception e){
300              unexpectedException();
301          }
302      }
303  
304      /**
305 <     * acquireExclusiveNanos on a locked lock times out
305 >     * tryAcquireNanos on a locked lock times out
306       */
307 <    public void testAcquireExclusiveNanos_Timeout() {
307 >    public void testAcquireNanos_Timeout() {
308          final Mutex lock = new Mutex();
309 <        lock.acquireExclusiveUninterruptibly(1);
309 >        lock.acquire(1);
310          Thread t = new Thread(new Runnable() {
311                  public void run() {
312                      try {
313 <                        threadAssertFalse(lock.acquireExclusiveNanos(1, 1000 * 1000));
313 >                        threadAssertFalse(lock.tryAcquireNanos(1, 1000 * 1000));
314                      } catch (Exception ex) {
315                          threadUnexpectedException();
316                      }
# Line 314 | Line 319 | public class AbstractQueuedSynchronizerT
319          try {
320              t.start();
321              t.join();
322 <            lock.releaseExclusive(1);
322 >            lock.release(1);
323          } catch(Exception e){
324              unexpectedException();
325          }
# Line 326 | Line 331 | public class AbstractQueuedSynchronizerT
331       */
332      public void testGetState() {
333          final Mutex lock = new Mutex();
334 <        lock.acquireExclusiveUninterruptibly(1);
335 <        assertTrue(lock.isLocked());
336 <        lock.releaseExclusive(1);
337 <        assertFalse(lock.isLocked());
334 >        lock.acquire(1);
335 >        assertTrue(lock.isHeldExclusively());
336 >        lock.release(1);
337 >        assertFalse(lock.isHeldExclusively());
338          Thread t = new Thread(new Runnable() {
339                  public void run() {
340 <                    lock.acquireExclusiveUninterruptibly(1);
340 >                    lock.acquire(1);
341                      try {
342                          Thread.sleep(SMALL_DELAY_MS);
343                      }
344                      catch(Exception e) {
345                          threadUnexpectedException();
346                      }
347 <                    lock.releaseExclusive(1);
347 >                    lock.release(1);
348                  }
349              });
350          try {
351              t.start();
352              Thread.sleep(SHORT_DELAY_MS);
353 <            assertTrue(lock.isLocked());
353 >            assertTrue(lock.isHeldExclusively());
354              t.join();
355 <            assertFalse(lock.isLocked());
355 >            assertFalse(lock.isHeldExclusively());
356          } catch(Exception e){
357              unexpectedException();
358          }
# Line 355 | Line 360 | public class AbstractQueuedSynchronizerT
360  
361  
362      /**
363 <     * acquireExclusiveInterruptibly is interruptible.
363 >     * acquireInterruptibly is interruptible.
364       */
365      public void testAcquireInterruptibly1() {
366          final Mutex lock = new Mutex();
367 <        lock.acquireExclusiveUninterruptibly(1);
367 >        lock.acquire(1);
368          Thread t = new Thread(new InterruptedLockRunnable(lock));
369          try {
370              t.start();
371              t.interrupt();
372 <            lock.releaseExclusive(1);
372 >            lock.release(1);
373              t.join();
374          } catch(Exception e){
375              unexpectedException();
# Line 372 | Line 377 | public class AbstractQueuedSynchronizerT
377      }
378  
379      /**
380 <     * acquireExclusiveInterruptibly succeeds when released, else is interruptible
380 >     * acquireInterruptibly succeeds when released, else is interruptible
381       */
382      public void testAcquireInterruptibly2() {
383          final Mutex lock = new Mutex();
384          try {
385 <            lock.acquireExclusiveInterruptibly(1);
385 >            lock.acquireInterruptibly(1);
386          } catch(Exception e) {
387              unexpectedException();
388          }
# Line 385 | Line 390 | public class AbstractQueuedSynchronizerT
390          try {
391              t.start();
392              t.interrupt();
393 <            assertTrue(lock.isLocked());
393 >            assertTrue(lock.isHeldExclusively());
394              t.join();
395          } catch(Exception e){
396              unexpectedException();
# Line 444 | Line 449 | public class AbstractQueuedSynchronizerT
449          final Mutex lock = new Mutex();
450          final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
451          try {
452 <            lock.acquireExclusiveUninterruptibly(1);
452 >            lock.acquire(1);
453              long t = c.awaitNanos(100);
454              assertTrue(t <= 0);
455 <            lock.releaseExclusive(1);
455 >            lock.release(1);
456          }
457          catch (Exception ex) {
458              unexpectedException();
# Line 461 | Line 466 | public class AbstractQueuedSynchronizerT
466          final Mutex lock = new Mutex();
467          final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
468          try {
469 <            lock.acquireExclusiveUninterruptibly(1);
469 >            lock.acquire(1);
470              assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
471 <            lock.releaseExclusive(1);
471 >            lock.release(1);
472          }
473          catch (Exception ex) {
474              unexpectedException();
# Line 477 | Line 482 | public class AbstractQueuedSynchronizerT
482          final Mutex lock = new Mutex();
483          final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
484          try {
485 <            lock.acquireExclusiveUninterruptibly(1);
485 >            lock.acquire(1);
486              java.util.Date d = new java.util.Date();
487              assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + 10)));
488 <            lock.releaseExclusive(1);
488 >            lock.release(1);
489          }
490          catch (Exception ex) {
491              unexpectedException();
# Line 496 | Line 501 | public class AbstractQueuedSynchronizerT
501          Thread t = new Thread(new Runnable() {
502                  public void run() {
503                      try {
504 <                        lock.acquireExclusiveUninterruptibly(1);
504 >                        lock.acquire(1);
505                          c.await();
506 <                        lock.releaseExclusive(1);
506 >                        lock.release(1);
507                      }
508                      catch(InterruptedException e) {
509                          threadUnexpectedException();
# Line 509 | Line 514 | public class AbstractQueuedSynchronizerT
514          try {
515              t.start();
516              Thread.sleep(SHORT_DELAY_MS);
517 <            lock.acquireExclusiveUninterruptibly(1);
517 >            lock.acquire(1);
518              c.signal();
519 <            lock.releaseExclusive(1);
519 >            lock.release(1);
520              t.join(SHORT_DELAY_MS);
521              assertFalse(t.isAlive());
522          }
# Line 672 | Line 677 | public class AbstractQueuedSynchronizerT
677          Thread t = new Thread(new Runnable() {
678                  public void run() {
679                      try {
680 <                        lock.acquireExclusiveUninterruptibly(1);
680 >                        lock.acquire(1);
681                          threadAssertFalse(lock.hasWaiters(c));
682                          threadAssertEquals(0, lock.getWaitQueueLength(c));
683                          c.await();
684 <                        lock.releaseExclusive(1);
684 >                        lock.release(1);
685                      }
686                      catch(InterruptedException e) {
687                          threadUnexpectedException();
# Line 687 | Line 692 | public class AbstractQueuedSynchronizerT
692          try {
693              t.start();
694              Thread.sleep(SHORT_DELAY_MS);
695 <            lock.acquireExclusiveUninterruptibly(1);
695 >            lock.acquire(1);
696              assertTrue(lock.hasWaiters(c));
697              assertEquals(1, lock.getWaitQueueLength(c));
698              c.signal();
699 <            lock.releaseExclusive(1);
699 >            lock.release(1);
700              Thread.sleep(SHORT_DELAY_MS);
701 <            lock.acquireExclusiveUninterruptibly(1);
701 >            lock.acquire(1);
702              assertFalse(lock.hasWaiters(c));
703              assertEquals(0, lock.getWaitQueueLength(c));
704 <            lock.releaseExclusive(1);
704 >            lock.release(1);
705              t.join(SHORT_DELAY_MS);
706              assertFalse(t.isAlive());
707          }
# Line 714 | Line 719 | public class AbstractQueuedSynchronizerT
719          Thread t1 = new Thread(new Runnable() {
720                  public void run() {
721                      try {
722 <                        lock.acquireExclusiveUninterruptibly(1);
722 >                        lock.acquire(1);
723                          threadAssertFalse(lock.hasWaiters(c));
724                          threadAssertEquals(0, lock.getWaitQueueLength(c));
725                          c.await();
726 <                        lock.releaseExclusive(1);
726 >                        lock.release(1);
727                      }
728                      catch(InterruptedException e) {
729                          threadUnexpectedException();
# Line 729 | Line 734 | public class AbstractQueuedSynchronizerT
734          Thread t2 = new Thread(new Runnable() {
735                  public void run() {
736                      try {
737 <                        lock.acquireExclusiveUninterruptibly(1);
737 >                        lock.acquire(1);
738                          threadAssertTrue(lock.hasWaiters(c));
739                          threadAssertEquals(1, lock.getWaitQueueLength(c));
740                          c.await();
741 <                        lock.releaseExclusive(1);
741 >                        lock.release(1);
742                      }
743                      catch(InterruptedException e) {
744                          threadUnexpectedException();
# Line 746 | Line 751 | public class AbstractQueuedSynchronizerT
751              Thread.sleep(SHORT_DELAY_MS);
752              t2.start();
753              Thread.sleep(SHORT_DELAY_MS);
754 <            lock.acquireExclusiveUninterruptibly(1);
754 >            lock.acquire(1);
755              assertTrue(lock.hasWaiters(c));
756              assertEquals(2, lock.getWaitQueueLength(c));
757              c.signalAll();
758 <            lock.releaseExclusive(1);
758 >            lock.release(1);
759              Thread.sleep(SHORT_DELAY_MS);
760 <            lock.acquireExclusiveUninterruptibly(1);
760 >            lock.acquire(1);
761              assertFalse(lock.hasWaiters(c));
762              assertEquals(0, lock.getWaitQueueLength(c));
763 <            lock.releaseExclusive(1);
763 >            lock.release(1);
764              t1.join(SHORT_DELAY_MS);
765              t2.join(SHORT_DELAY_MS);
766              assertFalse(t1.isAlive());
# Line 775 | Line 780 | public class AbstractQueuedSynchronizerT
780          Thread t1 = new Thread(new Runnable() {
781                  public void run() {
782                      try {
783 <                        lock.acquireExclusiveUninterruptibly(1);
783 >                        lock.acquire(1);
784                          threadAssertTrue(lock.getWaitingThreads(c).isEmpty());
785                          c.await();
786 <                        lock.releaseExclusive(1);
786 >                        lock.release(1);
787                      }
788                      catch(InterruptedException e) {
789                          threadUnexpectedException();
# Line 789 | Line 794 | public class AbstractQueuedSynchronizerT
794          Thread t2 = new Thread(new Runnable() {
795                  public void run() {
796                      try {
797 <                        lock.acquireExclusiveUninterruptibly(1);
797 >                        lock.acquire(1);
798                          threadAssertFalse(lock.getWaitingThreads(c).isEmpty());
799                          c.await();
800 <                        lock.releaseExclusive(1);
800 >                        lock.release(1);
801                      }
802                      catch(InterruptedException e) {
803                          threadUnexpectedException();
# Line 801 | Line 806 | public class AbstractQueuedSynchronizerT
806              });
807  
808          try {
809 <            lock.acquireExclusiveUninterruptibly(1);
809 >            lock.acquire(1);
810              assertTrue(lock.getWaitingThreads(c).isEmpty());
811 <            lock.releaseExclusive(1);
811 >            lock.release(1);
812              t1.start();
813              Thread.sleep(SHORT_DELAY_MS);
814              t2.start();
815              Thread.sleep(SHORT_DELAY_MS);
816 <            lock.acquireExclusiveUninterruptibly(1);
816 >            lock.acquire(1);
817              assertTrue(lock.hasWaiters(c));
818              assertTrue(lock.getWaitingThreads(c).contains(t1));
819              assertTrue(lock.getWaitingThreads(c).contains(t2));
820              c.signalAll();
821 <            lock.releaseExclusive(1);
821 >            lock.release(1);
822              Thread.sleep(SHORT_DELAY_MS);
823 <            lock.acquireExclusiveUninterruptibly(1);
823 >            lock.acquire(1);
824              assertFalse(lock.hasWaiters(c));
825              assertTrue(lock.getWaitingThreads(c).isEmpty());
826 <            lock.releaseExclusive(1);
826 >            lock.release(1);
827              t1.join(SHORT_DELAY_MS);
828              t2.join(SHORT_DELAY_MS);
829              assertFalse(t1.isAlive());
# Line 839 | Line 844 | public class AbstractQueuedSynchronizerT
844          final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
845          Thread t = new Thread(new Runnable() {
846                  public void run() {
847 <                    lock.acquireExclusiveUninterruptibly(1);
847 >                    lock.acquire(1);
848                      c.awaitUninterruptibly();
849 <                    lock.releaseExclusive(1);
849 >                    lock.release(1);
850                  }
851              });
852  
# Line 849 | Line 854 | public class AbstractQueuedSynchronizerT
854              t.start();
855              Thread.sleep(SHORT_DELAY_MS);
856              t.interrupt();
857 <            lock.acquireExclusiveUninterruptibly(1);
857 >            lock.acquire(1);
858              c.signal();
859 <            lock.releaseExclusive(1);
859 >            lock.release(1);
860              assert(t.isInterrupted());
861              t.join(SHORT_DELAY_MS);
862              assertFalse(t.isAlive());
# Line 870 | Line 875 | public class AbstractQueuedSynchronizerT
875          Thread t = new Thread(new Runnable() {
876                  public void run() {
877                      try {
878 <                        lock.acquireExclusiveUninterruptibly(1);
878 >                        lock.acquire(1);
879                          c.await();
880 <                        lock.releaseExclusive(1);
880 >                        lock.release(1);
881                          threadShouldThrow();
882                      }
883                      catch(InterruptedException success) {
# Line 901 | Line 906 | public class AbstractQueuedSynchronizerT
906          Thread t = new Thread(new Runnable() {
907                  public void run() {
908                      try {
909 <                        lock.acquireExclusiveUninterruptibly(1);
909 >                        lock.acquire(1);
910                          c.awaitNanos(1000 * 1000 * 1000); // 1 sec
911 <                        lock.releaseExclusive(1);
911 >                        lock.release(1);
912                          threadShouldThrow();
913                      }
914                      catch(InterruptedException success) {
# Line 932 | Line 937 | public class AbstractQueuedSynchronizerT
937          Thread t = new Thread(new Runnable() {
938                  public void run() {
939                      try {
940 <                        lock.acquireExclusiveUninterruptibly(1);
940 >                        lock.acquire(1);
941                          java.util.Date d = new java.util.Date();
942                          c.awaitUntil(new java.util.Date(d.getTime() + 10000));
943 <                        lock.releaseExclusive(1);
943 >                        lock.release(1);
944                          threadShouldThrow();
945                      }
946                      catch(InterruptedException success) {
# Line 964 | Line 969 | public class AbstractQueuedSynchronizerT
969          Thread t1 = new Thread(new Runnable() {
970                  public void run() {
971                      try {
972 <                        lock.acquireExclusiveUninterruptibly(1);
972 >                        lock.acquire(1);
973                          c.await();
974 <                        lock.releaseExclusive(1);
974 >                        lock.release(1);
975                      }
976                      catch(InterruptedException e) {
977                          threadUnexpectedException();
# Line 977 | Line 982 | public class AbstractQueuedSynchronizerT
982          Thread t2 = new Thread(new Runnable() {
983                  public void run() {
984                      try {
985 <                        lock.acquireExclusiveUninterruptibly(1);
985 >                        lock.acquire(1);
986                          c.await();
987 <                        lock.releaseExclusive(1);
987 >                        lock.release(1);
988                      }
989                      catch(InterruptedException e) {
990                          threadUnexpectedException();
# Line 991 | Line 996 | public class AbstractQueuedSynchronizerT
996              t1.start();
997              t2.start();
998              Thread.sleep(SHORT_DELAY_MS);
999 <            lock.acquireExclusiveUninterruptibly(1);
999 >            lock.acquire(1);
1000              c.signalAll();
1001 <            lock.releaseExclusive(1);
1001 >            lock.release(1);
1002              t1.join(SHORT_DELAY_MS);
1003              t2.join(SHORT_DELAY_MS);
1004              assertFalse(t1.isAlive());
# Line 1012 | Line 1017 | public class AbstractQueuedSynchronizerT
1017          Mutex lock = new Mutex();
1018          String us = lock.toString();
1019          assertTrue(us.indexOf("State = 0") >= 0);
1020 <        lock.acquireExclusiveUninterruptibly(1);
1020 >        lock.acquire(1);
1021          String ls = lock.toString();
1022          assertTrue(ls.indexOf("State = 1") >= 0);
1023      }
# Line 1022 | Line 1027 | public class AbstractQueuedSynchronizerT
1027       */
1028      public void testSerialization() {
1029          Mutex l = new Mutex();
1030 <        l.acquireExclusiveUninterruptibly(1);
1031 <        assertTrue(l.isLocked());
1030 >        l.acquire(1);
1031 >        assertTrue(l.isHeldExclusively());
1032  
1033          try {
1034              ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
# Line 1034 | Line 1039 | public class AbstractQueuedSynchronizerT
1039              ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1040              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1041              Mutex r = (Mutex) in.readObject();
1042 <            assertTrue(r.isLocked());
1042 >            assertTrue(r.isHeldExclusively());
1043          } catch(Exception e){
1044              e.printStackTrace();
1045              unexpectedException();
# Line 1104 | Line 1109 | public class AbstractQueuedSynchronizerT
1109                  public void run() {
1110                      try {
1111                          threadAssertFalse(l.isSignalled());
1112 <                        threadAssertTrue(l.acquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
1112 >                        threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
1113                          threadAssertTrue(l.isSignalled());
1114  
1115                      } catch(InterruptedException e){
# Line 1157 | Line 1162 | public class AbstractQueuedSynchronizerT
1162                  public void run() {
1163                      try {
1164                          threadAssertFalse(l.isSignalled());
1165 <                        l.acquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000);
1165 >                        l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000);
1166                          threadShouldThrow();                        
1167                      } catch(InterruptedException success){}
1168                  }
# Line 1182 | Line 1187 | public class AbstractQueuedSynchronizerT
1187                  public void run() {
1188                      try {
1189                          threadAssertFalse(l.isSignalled());
1190 <                        threadAssertFalse(l.acquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1190 >                        threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1191                      } catch(InterruptedException ie){
1192                          threadUnexpectedException();
1193                      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines