Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
          +++ new/src/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
↓ open down ↓ 982 lines elided ↑ open up ↑
 983  983       * success.  Otherwise the thread is queued, possibly repeatedly
 984  984       * blocking and unblocking, invoking {@link #tryAcquire}
 985  985       * until success or the thread is interrupted.  This method can be
 986  986       * used to implement method {@link Lock#lockInterruptibly}.
 987  987       *
 988  988       * @param arg the acquire argument.  This value is conveyed to
 989  989       *        {@link #tryAcquire} but is otherwise uninterpreted and
 990  990       *        can represent anything you like.
 991  991       * @throws InterruptedException if the current thread is interrupted
 992  992       */
 993      -    public final void acquireInterruptibly(long arg) throws InterruptedException {
      993 +    public final void acquireInterruptibly(long arg)
      994 +            throws InterruptedException {
 994  995          if (Thread.interrupted())
 995  996              throw new InterruptedException();
 996  997          if (!tryAcquire(arg))
 997  998              doAcquireInterruptibly(arg);
 998  999      }
 999 1000  
1000 1001      /**
1001 1002       * Attempts to acquire in exclusive mode, aborting if interrupted,
1002 1003       * and failing if the given timeout elapses.  Implemented by first
1003 1004       * checking interrupt status, then invoking at least once {@link
↓ open down ↓ 3 lines elided ↑ open up ↑
1007 1008       * or the timeout elapses.  This method can be used to implement
1008 1009       * method {@link Lock#tryLock(long, TimeUnit)}.
1009 1010       *
1010 1011       * @param arg the acquire argument.  This value is conveyed to
1011 1012       *        {@link #tryAcquire} but is otherwise uninterpreted and
1012 1013       *        can represent anything you like.
1013 1014       * @param nanosTimeout the maximum number of nanoseconds to wait
1014 1015       * @return {@code true} if acquired; {@code false} if timed out
1015 1016       * @throws InterruptedException if the current thread is interrupted
1016 1017       */
1017      -    public final boolean tryAcquireNanos(long arg, long nanosTimeout) throws InterruptedException {
     1018 +    public final boolean tryAcquireNanos(long arg, long nanosTimeout)
     1019 +            throws InterruptedException {
1018 1020          if (Thread.interrupted())
1019 1021              throw new InterruptedException();
1020 1022          return tryAcquire(arg) ||
1021 1023              doAcquireNanos(arg, nanosTimeout);
1022 1024      }
1023 1025  
1024 1026      /**
1025 1027       * Releases in exclusive mode.  Implemented by unblocking one or
1026 1028       * more threads if {@link #tryRelease} returns true.
1027 1029       * This method can be used to implement method {@link Lock#unlock}.
↓ open down ↓ 35 lines elided ↑ open up ↑
1063 1065       * {@link #tryAcquireShared}, returning on success.  Otherwise the
1064 1066       * thread is queued, possibly repeatedly blocking and unblocking,
1065 1067       * invoking {@link #tryAcquireShared} until success or the thread
1066 1068       * is interrupted.
1067 1069       * @param arg the acquire argument
1068 1070       * This value is conveyed to {@link #tryAcquireShared} but is
1069 1071       * otherwise uninterpreted and can represent anything
1070 1072       * you like.
1071 1073       * @throws InterruptedException if the current thread is interrupted
1072 1074       */
1073      -    public final void acquireSharedInterruptibly(long arg) throws InterruptedException {
     1075 +    public final void acquireSharedInterruptibly(long arg)
     1076 +            throws InterruptedException {
1074 1077          if (Thread.interrupted())
1075 1078              throw new InterruptedException();
1076 1079          if (tryAcquireShared(arg) < 0)
1077 1080              doAcquireSharedInterruptibly(arg);
1078 1081      }
1079 1082  
1080 1083      /**
1081 1084       * Attempts to acquire in shared mode, aborting if interrupted, and
1082 1085       * failing if the given timeout elapses.  Implemented by first
1083 1086       * checking interrupt status, then invoking at least once {@link
↓ open down ↓ 2 lines elided ↑ open up ↑
1086 1089       * invoking {@link #tryAcquireShared} until success or the thread
1087 1090       * is interrupted or the timeout elapses.
1088 1091       *
1089 1092       * @param arg the acquire argument.  This value is conveyed to
1090 1093       *        {@link #tryAcquireShared} but is otherwise uninterpreted
1091 1094       *        and can represent anything you like.
1092 1095       * @param nanosTimeout the maximum number of nanoseconds to wait
1093 1096       * @return {@code true} if acquired; {@code false} if timed out
1094 1097       * @throws InterruptedException if the current thread is interrupted
1095 1098       */
1096      -    public final boolean tryAcquireSharedNanos(long arg, long nanosTimeout) throws InterruptedException {
     1099 +    public final boolean tryAcquireSharedNanos(long arg, long nanosTimeout)
     1100 +            throws InterruptedException {
1097 1101          if (Thread.interrupted())
1098 1102              throw new InterruptedException();
1099 1103          return tryAcquireShared(arg) >= 0 ||
1100 1104              doAcquireSharedNanos(arg, nanosTimeout);
1101 1105      }
1102 1106  
1103 1107      /**
1104 1108       * Releases in shared mode.  Implemented by unblocking one or more
1105 1109       * threads if {@link #tryReleaseShared} returns true.
1106 1110       *
↓ open down ↓ 727 lines elided ↑ open up ↑
1834 1838           * <li> Save lock state returned by {@link #getState}.
1835 1839           * <li> Invoke {@link #release} with
1836 1840           *      saved state as argument, throwing
1837 1841           *      IllegalMonitorStateException if it fails.
1838 1842           * <li> Block until signalled, interrupted, or timed out.
1839 1843           * <li> Reacquire by invoking specialized version of
1840 1844           *      {@link #acquire} with saved state as argument.
1841 1845           * <li> If interrupted while blocked in step 4, throw InterruptedException.
1842 1846           * </ol>
1843 1847           */
1844      -        public final long awaitNanos(long nanosTimeout) throws InterruptedException {
     1848 +        public final long awaitNanos(long nanosTimeout)
     1849 +                throws InterruptedException {
1845 1850              if (Thread.interrupted())
1846 1851                  throw new InterruptedException();
1847 1852              Node node = addConditionWaiter();
1848 1853              long savedState = fullyRelease(node);
1849 1854              long lastTime = System.nanoTime();
1850 1855              int interruptMode = 0;
1851 1856              while (!isOnSyncQueue(node)) {
1852 1857                  if (nanosTimeout <= 0L) {
1853 1858                      transferAfterCancelledWait(node);
1854 1859                      break;
↓ open down ↓ 23 lines elided ↑ open up ↑
1878 1883           * <li> Invoke {@link #release} with
1879 1884           *      saved state as argument, throwing
1880 1885           *      IllegalMonitorStateException if it fails.
1881 1886           * <li> Block until signalled, interrupted, or timed out.
1882 1887           * <li> Reacquire by invoking specialized version of
1883 1888           *      {@link #acquire} with saved state as argument.
1884 1889           * <li> If interrupted while blocked in step 4, throw InterruptedException.
1885 1890           * <li> If timed out while blocked in step 4, return false, else true.
1886 1891           * </ol>
1887 1892           */
1888      -        public final boolean awaitUntil(Date deadline) throws InterruptedException {
     1893 +        public final boolean awaitUntil(Date deadline)
     1894 +                throws InterruptedException {
1889 1895              if (deadline == null)
1890 1896                  throw new NullPointerException();
1891 1897              long abstime = deadline.getTime();
1892 1898              if (Thread.interrupted())
1893 1899                  throw new InterruptedException();
1894 1900              Node node = addConditionWaiter();
1895 1901              long savedState = fullyRelease(node);
1896 1902              boolean timedout = false;
1897 1903              int interruptMode = 0;
1898 1904              while (!isOnSyncQueue(node)) {
↓ open down ↓ 22 lines elided ↑ open up ↑
1921 1927           * <li> Invoke {@link #release} with
1922 1928           *      saved state as argument, throwing
1923 1929           *      IllegalMonitorStateException if it fails.
1924 1930           * <li> Block until signalled, interrupted, or timed out.
1925 1931           * <li> Reacquire by invoking specialized version of
1926 1932           *      {@link #acquire} with saved state as argument.
1927 1933           * <li> If interrupted while blocked in step 4, throw InterruptedException.
1928 1934           * <li> If timed out while blocked in step 4, return false, else true.
1929 1935           * </ol>
1930 1936           */
1931      -        public final boolean await(long time, TimeUnit unit) throws InterruptedException {
     1937 +        public final boolean await(long time, TimeUnit unit)
     1938 +                throws InterruptedException {
1932 1939              if (unit == null)
1933 1940                  throw new NullPointerException();
1934 1941              long nanosTimeout = unit.toNanos(time);
1935 1942              if (Thread.interrupted())
1936 1943                  throw new InterruptedException();
1937 1944              Node node = addConditionWaiter();
1938 1945              long savedState = fullyRelease(node);
1939 1946              long lastTime = System.nanoTime();
1940 1947              boolean timedout = false;
1941 1948              int interruptMode = 0;
↓ open down ↓ 135 lines elided ↑ open up ↑
2077 2084      /**
2078 2085       * CAS tail field. Used only by enq.
2079 2086       */
2080 2087      private final boolean compareAndSetTail(Node expect, Node update) {
2081 2088          return unsafe.compareAndSwapObject(this, tailOffset, expect, update);
2082 2089      }
2083 2090  
2084 2091      /**
2085 2092       * CAS waitStatus field of a node.
2086 2093       */
2087      -    private final static boolean compareAndSetWaitStatus(Node node,
     2094 +    private static final boolean compareAndSetWaitStatus(Node node,
2088 2095                                                           int expect,
2089 2096                                                           int update) {
2090 2097          return unsafe.compareAndSwapInt(node, waitStatusOffset,
2091 2098                                          expect, update);
2092 2099      }
2093 2100  
2094 2101      /**
2095 2102       * CAS next field of a node.
2096 2103       */
2097      -    private final static boolean compareAndSetNext(Node node,
     2104 +    private static final boolean compareAndSetNext(Node node,
2098 2105                                                     Node expect,
2099 2106                                                     Node update) {
2100 2107          return unsafe.compareAndSwapObject(node, nextOffset, expect, update);
2101 2108      }
2102 2109  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX