Refactoring that is likely to help JVM optimize QNode more aggressively
This commit is contained in:
parent
67d90615e1
commit
42afa85e53
@ -158,18 +158,19 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E> implements Blocking
|
||||
}
|
||||
|
||||
boolean casNext(QNode cmp, QNode val) {
|
||||
if (nextUpdater == null) {
|
||||
// Safe mode.
|
||||
synchronized (this) {
|
||||
if (next == cmp) {
|
||||
next = val;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (nextUpdater != null) {
|
||||
return nextUpdater.compareAndSet(this, cmp, val);
|
||||
} else {
|
||||
return alternativeCasNext(cmp, val);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized boolean alternativeCasNext(QNode cmp, QNode val) {
|
||||
if (next == cmp) {
|
||||
next = val;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user