Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/Semaphore.java
          +++ new/src/share/classes/java/util/concurrent/Semaphore.java
↓ open down ↓ 215 lines elided ↑ open up ↑
 216  216                  int current = getState();
 217  217                  if (current == 0 || compareAndSetState(current, 0))
 218  218                      return current;
 219  219              }
 220  220          }
 221  221      }
 222  222  
 223  223      /**
 224  224       * NonFair version
 225  225       */
 226      -    final static class NonfairSync extends Sync {
      226 +    static final class NonfairSync extends Sync {
 227  227          private static final long serialVersionUID = -2694183684443567898L;
 228  228  
 229  229          NonfairSync(int permits) {
 230  230              super(permits);
 231  231          }
 232  232  
 233  233          protected int tryAcquireShared(int acquires) {
 234  234              return nonfairTryAcquireShared(acquires);
 235  235          }
 236  236      }
 237  237  
 238  238      /**
 239  239       * Fair version
 240  240       */
 241      -    final static class FairSync extends Sync {
      241 +    static final class FairSync extends Sync {
 242  242          private static final long serialVersionUID = 2014338818796000944L;
 243  243  
 244  244          FairSync(int permits) {
 245  245              super(permits);
 246  246          }
 247  247  
 248  248          protected int tryAcquireShared(int acquires) {
 249  249              for (;;) {
 250  250                  if (hasQueuedPredecessors())
 251  251                      return -1;
↓ open down ↓ 23 lines elided ↑ open up ↑
 275  275       * permits and the given fairness setting.
 276  276       *
 277  277       * @param permits the initial number of permits available.
 278  278       *        This value may be negative, in which case releases
 279  279       *        must occur before any acquires will be granted.
 280  280       * @param fair {@code true} if this semaphore will guarantee
 281  281       *        first-in first-out granting of permits under contention,
 282  282       *        else {@code false}
 283  283       */
 284  284      public Semaphore(int permits, boolean fair) {
 285      -        sync = (fair)? new FairSync(permits) : new NonfairSync(permits);
      285 +        sync = fair ? new FairSync(permits) : new NonfairSync(permits);
 286  286      }
 287  287  
 288  288      /**
 289  289       * Acquires a permit from this semaphore, blocking until one is
 290  290       * available, or the thread is {@linkplain Thread#interrupt interrupted}.
 291  291       *
 292  292       * <p>Acquires a permit, if one is available and returns immediately,
 293  293       * reducing the number of available permits by one.
 294  294       *
 295  295       * <p>If no permit is available then the current thread becomes
↓ open down ↓ 418 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX