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

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.162 by jsr166, Sun Oct 4 04:40:00 2015 UTC vs.
Revision 1.163 by jsr166, Sun Oct 4 05:52:08 2015 UTC

# Line 749 | Line 749 | public class JSR166TestCase extends Test
749      /**
750       * Delays, via Thread.sleep, for the given millisecond delay, but
751       * if the sleep is shorter than specified, may re-sleep or yield
752 <     * until time elapses.
752 >     * until time elapses.  Ensures that the given time, as measured
753 >     * by System.nanoTime(), has elapsed.
754       */
755      static void delay(long millis) throws InterruptedException {
756 <        long startTime = System.nanoTime();
757 <        long ns = millis * 1000 * 1000;
758 <        for (;;) {
756 >        long nanos = millis * (1000 * 1000);
757 >        final long wakeupTime = System.nanoTime() + nanos;
758 >        do {
759              if (millis > 0L)
760                  Thread.sleep(millis);
761              else // too short to sleep
762                  Thread.yield();
763 <            long d = ns - (System.nanoTime() - startTime);
764 <            if (d > 0L)
765 <                millis = d / (1000 * 1000);
765 <            else
766 <                break;
767 <        }
763 >            nanos = wakeupTime - System.nanoTime();
764 >            millis = nanos / (1000 * 1000);
765 >        } while (nanos >= 0L);
766      }
767  
768      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines