Created
September 25, 2019 03:20
-
-
Save bbakerman/dec25045c5750177641ad6bc3b30e4df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int b, h; ForkJoinTask<?>[] a; Object o; | |
if ((b = base) - top >= 0 || (a = array) == null) | |
h = b | Integer.MIN_VALUE; // to sense movement on re-poll | |
else { | |
long j = (((a.length - 1) & b) << ASHIFT) + ABASE; | |
if ((o = U.getObjectVolatile(a, j)) == null) | |
h = 2; // retryable | |
else if (!(o instanceof CountedCompleter)) | |
h = -1; // unmatchable | |
else { | |
CountedCompleter<?> t = (CountedCompleter<?>)o; | |
for (CountedCompleter<?> r = t;;) { | |
if (r == task) { | |
if (base == b && | |
U.compareAndSwapObject(a, j, t, null)) { | |
base = b + 1; | |
t.doExec(); | |
h = 1; // success | |
} | |
else | |
h = 2; // lost CAS | |
break; | |
} | |
else if ((r = r.completer) == null) { | |
h = -1; // unmatched | |
break; | |
} | |
} | |
} | |
} | |
return h; | |
int s; ForkJoinTask<?>[] a; Object o; | |
if (base - (s = top) < 0 && (a = array) != null) { | |
long j = (((a.length - 1) & (s - 1)) << ASHIFT) + ABASE; | |
if ((o = U.getObjectVolatile(a, j)) != null && | |
(o instanceof CountedCompleter)) { | |
CountedCompleter<?> t = (CountedCompleter<?>)o; | |
for (CountedCompleter<?> r = t;;) { | |
if (r == task) { | |
if (mode < 0) { // must lock | |
if (U.compareAndSwapInt(this, QLOCK, 0, 1)) { | |
if (top == s && array == a && | |
U.compareAndSwapObject(a, j, t, null)) { | |
U.putOrderedInt(this, QTOP, s - 1); | |
U.putOrderedInt(this, QLOCK, 0); | |
return t; | |
} | |
U.compareAndSwapInt(this, QLOCK, 1, 0); | |
} | |
} | |
else if (U.compareAndSwapObject(a, j, t, null)) { | |
U.putOrderedInt(this, QTOP, s - 1); | |
return t; | |
} | |
break; | |
} | |
else if ((r = r.completer) == null) // try parent | |
break; | |
} | |
} | |
} | |
return null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment