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

Comparing jsr166/src/main/java/util/concurrent/SynchronousQueue.java (file contents):
Revision 1.32 by dl, Wed Dec 31 21:30:00 2003 UTC vs.
Revision 1.33 by dl, Fri Jan 2 00:38:33 2004 UTC

# Line 99 | Line 99 | public class SynchronousQueue<E> extends
99          /**
100           * Implements AQS base release to always signal.
101           * Status is changed in ack or cancel methods before calling,
102 <         * which is needed to handle cancellation races.
102 >         * Which we need to do because we need their return values.
103           */
104          public boolean releaseExclusiveState(int ignore) {
105              return true;
# Line 149 | Line 149 | public class SynchronousQueue<E> extends
149           * to continue.
150           */
151          Object getItem() {
152 <            if (!ack())
153 <                return null;
154 <            return extract();
152 >            return (ack())? extract() : null;
153          }
154  
155          /**
156 <         * Wait for a taker to take item placed by putter.
156 >         * Wait for a taker to take item placed by putter or time out.
157           */
158 <        boolean waitForTake() throws InterruptedException {
158 >        boolean waitForTake(boolean timed, long nanos) throws InterruptedException {
159              try {
160 <                acquireExclusiveInterruptibly(0);
160 >                if (!timed)
161 >                    acquireExclusiveInterruptibly(0);
162 >                else if (!acquireExclusiveTimed(0, nanos) && cancel())
163 >                    return false;
164                  return true;
165              } catch (InterruptedException ie) {
166                  if (cancel())
# Line 170 | Line 171 | public class SynchronousQueue<E> extends
171          }
172  
173          /**
174 <         * Wait for a taker to take item placed by putter, or time out.
174 <         */
175 <        boolean waitForTake(long nanos) throws InterruptedException {
176 <            try {
177 <                return acquireExclusiveTimed(0, nanos) || !cancel();
178 <            } catch (InterruptedException ie) {
179 <                if (cancel())
180 <                    throw ie;
181 <                Thread.currentThread().interrupt();
182 <                return true;
183 <            }
184 <        }
185 <
186 <        /**
187 <         * Wait for a putter to put item placed by taker.
174 >         * Wait for a putter to put item placed by taker, or time out.
175           */
176 <        Object waitForPut() throws InterruptedException {
176 >        Object waitForPut(boolean timed, long nanos) throws InterruptedException {
177              try {
178 <                acquireExclusiveInterruptibly(0);
178 >                if (!timed)
179 >                    acquireExclusiveInterruptibly(0);
180 >                else if (!acquireExclusiveTimed(0, nanos) && cancel())
181 >                    return null;
182                  return extract();
183              } catch (InterruptedException ie) {
184                  if (cancel())
# Line 198 | Line 188 | public class SynchronousQueue<E> extends
188              }
189          }
190  
201        /**
202         * Wait for a putter to put item placed by taker, or time out.
203         */
204        Object waitForPut(long nanos) throws InterruptedException {
205            try {
206                if (acquireExclusiveTimed(0, nanos) || !cancel())
207                    return extract();
208                return null;
209            } catch (InterruptedException ie) {
210                if (cancel())
211                    throw ie;
212                Thread.currentThread().interrupt();
213                return extract();
214            }
215        }
191      }
192  
193      /**
# Line 258 | Line 233 | public class SynchronousQueue<E> extends
233              }
234  
235              if (mustWait)
236 <                return timed? node.waitForTake(nanos) : node.waitForTake();
236 >                return  node.waitForTake(timed, nanos);
237  
238              else if (node.setItem(x))
239                  return true;
# Line 286 | Line 261 | public class SynchronousQueue<E> extends
261              }
262  
263              if (mustWait) {
264 <                Object x = timed? node.waitForPut(nanos) : node.waitForPut();
264 >                Object x = node.waitForPut(timed, nanos);
265                  return (E)x;
266              }
267              else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines