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.53 by jsr166, Sun May 18 23:47:56 2008 UTC vs.
Revision 1.54 by jsr166, Wed Apr 7 19:24:40 2010 UTC

# Line 162 | Line 162 | public class Semaphore implements java.i
162  
163          protected final boolean tryReleaseShared(int releases) {
164              for (;;) {
165 <                int p = getState();
166 <                if (compareAndSetState(p, p + releases))
165 >                int current = getState();
166 >                int next = current + releases;
167 >                if (next < current) // overflow
168 >                    throw new Error("Maximum permit count exceeded");
169 >                if (compareAndSetState(current, next))
170                      return true;
171              }
172          }
# Line 172 | Line 175 | public class Semaphore implements java.i
175              for (;;) {
176                  int current = getState();
177                  int next = current - reductions;
178 +                if (next > current) // underflow
179 +                    throw new Error("Permit count underflow");
180                  if (compareAndSetState(current, next))
181                      return;
182              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines