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

Comparing jsr166/src/main/java/util/concurrent/Exchanger.java (file contents):
Revision 1.55 by dl, Fri Dec 23 19:33:45 2011 UTC vs.
Revision 1.56 by jsr166, Fri Dec 23 20:43:21 2011 UTC

# Line 79 | Line 79 | public class Exchanger<V> {
79       * Oveview: The core algorithm is, for an exchange "slot",
80       * and a participant (caller) with an item:
81       *
82 <     *   for(;;) {
82 >     *   for (;;) {
83       *       if (slot is empty) {                       // offer
84       *           place item in a Node;
85       *           if (can CAS slot from empty to node) {
# Line 348 | Line 348 | public class Exchanger<V> {
348              else if (i <= (m = (b = bound) & MMASK) && q == null) {
349                  p.item = item;                         // offer
350                  if (U.compareAndSwapObject(a, j, null, p)) {
351 <                    long end = (timed && m == 0)? System.nanoTime() + ns : 0L;
351 >                    long end = (timed && m == 0) ? System.nanoTime() + ns : 0L;
352                      Thread t = Thread.currentThread(); // wait
353                      for (int h = p.hash, spins = SPINS;;) {
354                          Object v = p.match;
# Line 457 | Line 457 | public class Exchanger<V> {
457  
458          // await release
459          int h = p.hash;
460 <        long end = timed? System.nanoTime() + ns : 0L;
460 >        long end = timed ? System.nanoTime() + ns : 0L;
461          int spins = (NCPU > 1) ? SPINS : 1;
462          Object v;
463          while ((v = p.match) == null) {
# Line 533 | Line 533 | public class Exchanger<V> {
533      @SuppressWarnings("unchecked")
534      public V exchange(V x) throws InterruptedException {
535          Object v;
536 <        Object item = (x == null)? NULL_ITEM : x; // translate null args
536 >        Object item = (x == null) ? NULL_ITEM : x; // translate null args
537          if ((arena != null ||
538               (v = slotExchange(item, false, 0L)) == null) &&
539              ((Thread.interrupted() || // disambiguates null return
540                (v = arenaExchange(item, false, 0L)) == null)))
541              throw new InterruptedException();
542 <        return (v == NULL_ITEM)? null : (V)v;
542 >        return (v == NULL_ITEM) ? null : (V)v;
543      }
544  
545      /**
# Line 588 | Line 588 | public class Exchanger<V> {
588      public V exchange(V x, long timeout, TimeUnit unit)
589          throws InterruptedException, TimeoutException {
590          Object v;
591 <        Object item = (x == null)? NULL_ITEM : x;
591 >        Object item = (x == null) ? NULL_ITEM : x;
592          long ns = unit.toNanos(timeout);
593          if ((arena != null ||
594               (v = slotExchange(item, true, ns)) == null) &&
# Line 597 | Line 597 | public class Exchanger<V> {
597              throw new InterruptedException();
598          if (v == TIMED_OUT)
599              throw new TimeoutException();
600 <        return (v == NULL_ITEM)? null : (V)v;
600 >        return (v == NULL_ITEM) ? null : (V)v;
601      }
602  
603      // Unsafe mechanics

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines