summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2014-09-05 13:13:35 -0700
committerMathieu Chartier <mathieuc@google.com>2014-09-05 14:32:46 -0700
commit365ea82a5c83d18f1630b7cf232f8499d9613dc0 (patch)
tree02e2cdc25daf42d95a3445a130910e2589c35197
parentd0ce966016703de5783ac5097131d7a738d8b007 (diff)
downloadlibcore-365ea82a5c83d18f1630b7cf232f8499d9613dc0.zip
libcore-365ea82a5c83d18f1630b7cf232f8499d9613dc0.tar.gz
libcore-365ea82a5c83d18f1630b7cf232f8499d9613dc0.tar.bz2
Change ReferenceQueue.add to append at end of the unenqueued list
We now append the singly linked list at the end of the queue. Previously the list was added after the first element of the unenqueued list. Bug: 17381967 (cherry picked from commit 37477444ae4d6fae52258f9ea85d32d5a87ebef2) Change-Id: Ie6680df476518236037254546380a8255ad801ac
-rw-r--r--luni/src/main/java/java/lang/ref/ReferenceQueue.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/luni/src/main/java/java/lang/ref/ReferenceQueue.java b/luni/src/main/java/java/lang/ref/ReferenceQueue.java
index 7ddd97d..4c78fbf 100644
--- a/luni/src/main/java/java/lang/ref/ReferenceQueue.java
+++ b/luni/src/main/java/java/lang/ref/ReferenceQueue.java
@@ -153,9 +153,18 @@ public class ReferenceQueue<T> {
if (unenqueued == null) {
unenqueued = list;
} else {
- Reference<?> next = unenqueued.pendingNext;
- unenqueued.pendingNext = list.pendingNext;
- list.pendingNext = next;
+ // Find the last element in unenqueued.
+ Reference<?> last = unenqueued;
+ while (last.pendingNext != unenqueued) {
+ last = last.pendingNext;
+ }
+ // Add our list to the end. Update the pendingNext to point back to enqueued.
+ last.pendingNext = list;
+ last = list;
+ while (last.pendingNext != list) {
+ last = last.pendingNext;
+ }
+ last.pendingNext = unenqueued;
}
ReferenceQueue.class.notifyAll();
}