ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/StripedAdder.java
(Generate patch)

Comparing jsr166/src/jsr166e/StripedAdder.java (file contents):
Revision 1.10 by dl, Fri Jul 29 13:50:54 2011 UTC vs.
Revision 1.11 by dl, Fri Jul 29 14:23:35 2011 UTC

# Line 209 | Line 209 | public class StripedAdder implements Ser
209              Adder[] as; Adder a; int n;
210              if ((as = adders) != null && (n = as.length) > 0) {
211                  if ((a = as[(n - 1) & h]) == null) {
212 <                    if (busy == 0 &&            // Try to attach new Adder
213 <                        UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1)) {
214 <                        boolean created = false;
215 <                        try {                   // Recheck under lock
216 <                            Adder[] rs; int m, j;
217 <                            if ((rs = adders) != null && (m = rs.length) > 0 &&
218 <                                rs[j = (m - 1) & h] == null) {
219 <                                rs[j] = new Adder(x);
220 <                                created = true;
212 >                    if (busy == 0) {            // Try to attach new Adder
213 >                        Adder r = new Adder(x); // Optimistically create
214 >                        if (busy == 0 &&
215 >                            UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1)) {
216 >                            boolean created = false;
217 >                            try {               // Recheck under lock
218 >                                Adder[] rs; int m, j;
219 >                                if ((rs = adders) != null &&
220 >                                    (m = rs.length) > 0 &&
221 >                                    rs[j = (m - 1) & h] == null) {
222 >                                    rs[j] = r;
223 >                                    created = true;
224 >                                }
225 >                            } finally {
226 >                                busy = 0;
227                              }
228 <                        } finally {
229 <                            busy = 0;
228 >                            if (created)
229 >                                break;
230 >                            continue;           // Slot is now non-empty
231                          }
225                        if (created)
226                            break;
227                        continue;               // Slot is now non-empty
232                      }
233                      collide = false;
234                  }
# Line 237 | Line 241 | public class StripedAdder implements Ser
241                      if (!collide)
242                          collide = true;
243                      else if (n >= NCPU || adders != as)
244 <                        collide = false;        // Don't expand
244 >                        collide = false;        // Can't expand
245                      else if (busy == 0 &&
246                               UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1)) {
247                          collide = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines