ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/Semaphore.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/Semaphore.java (file contents):
Revision 1.24 by dl, Sat Dec 27 19:26:26 2003 UTC vs.
Revision 1.25 by dl, Sun Dec 28 15:53:16 2003 UTC

# Line 120 | Line 120 | import java.util.concurrent.atomic.*;
120  
121   public class Semaphore implements java.io.Serializable {
122      private static final long serialVersionUID = -3222578661600680210L;
123 <    /** Sync mechanics via AbstractQueuedSynchronizer subclass */
123 >    /** All mechanics via AbstractQueuedSynchronizer subclass */
124      private final Sync sync;
125  
126 <
126 >    /**
127 >     * Synchronization implementation for semaphore
128 >     */
129      private final static class Sync extends AbstractQueuedSynchronizer {
130          final boolean fair;
131          Sync(int permits, boolean fair) {
132              this.fair = fair;
133 <            getState().set(permits);
133 >            state().set(permits);
134          }
135          
136          public final int acquireSharedState(boolean isQueued, int acquires,
137                                              Thread current) {
138 <            final AtomicInteger perms = getState();
139 <            if (!isQueued && fair && hasWaiters())
138 >            final AtomicInteger perms = state();
139 >            if (!isQueued && fair && hasQueuedThreads())
140                  return -1;
141              for (;;) {
142                  int available = perms.get();
# Line 146 | Line 148 | public class Semaphore implements java.i
148          }
149          
150          public final boolean releaseSharedState(int releases) {
151 <            final AtomicInteger perms = getState();
151 >            final AtomicInteger perms = state();
152              for (;;) {
153                  int p = perms.get();
154                  if (perms.compareAndSet(p, p + releases))
# Line 167 | Line 169 | public class Semaphore implements java.i
169          public final void checkConditionAccess(Thread thread, boolean waiting) {
170              throw new UnsupportedOperationException();
171          }
170
172      }
173  
174      /**
# Line 506 | Line 507 | public class Semaphore implements java.i
507       * @return the number of permits available in this semaphore.
508       */
509      public int availablePermits() {
510 <        return sync.getState().get();
510 >        return sync.state().get();
511      }
512  
513      /**
# Line 521 | Line 522 | public class Semaphore implements java.i
522       */
523      protected void reducePermits(int reduction) {
524          if (reduction < 0) throw new IllegalArgumentException();
525 <        sync.getState().getAndAdd(-reduction);
525 >        sync.state().getAndAdd(-reduction);
526      }
527  
528      /**
# Line 543 | Line 544 | public class Semaphore implements java.i
544       * @return true if there may be other threads waiting to acquire
545       * the lock.
546       */
547 <    public final boolean hasWaiters() {
548 <        return sync.hasWaiters();
547 >    public final boolean hasQueuedThreads() {
548 >        return sync.hasQueuedThreads();
549      }
550  
551  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines