summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-05-07 09:06:19 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-05-07 09:06:19 +0000
commitd8eb43c1072f8467ae01ab93944c1032c94c6ccc (patch)
tree3307a327ff535c19bffbca860d3e03dd0bd7080d
parentdb3cbbc355adbe08926881ef86a1e18fa6a475b1 (diff)
parenteb3e5888d4b3c17b5b6e977440178e88ba174f93 (diff)
downloadlibcore-d8eb43c1072f8467ae01ab93944c1032c94c6ccc.zip
libcore-d8eb43c1072f8467ae01ab93944c1032c94c6ccc.tar.gz
libcore-d8eb43c1072f8467ae01ab93944c1032c94c6ccc.tar.bz2
Merge "Change ReferenceQueue order from LIFO to FIFO."
-rw-r--r--luni/src/main/java/java/lang/ref/ReferenceQueue.java21
1 files changed, 12 insertions, 9 deletions
diff --git a/luni/src/main/java/java/lang/ref/ReferenceQueue.java b/luni/src/main/java/java/lang/ref/ReferenceQueue.java
index 2b8089c..7ddd97d 100644
--- a/luni/src/main/java/java/lang/ref/ReferenceQueue.java
+++ b/luni/src/main/java/java/lang/ref/ReferenceQueue.java
@@ -28,6 +28,7 @@ public class ReferenceQueue<T> {
private static final int NANOS_PER_MILLI = 1000000;
private Reference<? extends T> head;
+ private Reference<? extends T> tail;
/**
* Constructs a new instance of this class.
@@ -48,18 +49,16 @@ public class ReferenceQueue<T> {
return null;
}
- Reference<? extends T> ret;
+ Reference<? extends T> ret = head;
- ret = head;
-
- if (head == head.queueNext) {
+ if (head == tail) {
+ tail = null;
head = null;
} else {
head = head.queueNext;
}
ret.queueNext = null;
-
return ret;
}
@@ -133,12 +132,16 @@ public class ReferenceQueue<T> {
* reference object to be enqueued.
*/
synchronized void enqueue(Reference<? extends T> reference) {
- if (head == null) {
- reference.queueNext = reference;
+ if (tail == null) {
+ head = reference;
} else {
- reference.queueNext = head;
+ tail.queueNext = reference;
}
- head = reference;
+
+ // The newly enqueued reference becomes the new tail, and always
+ // points to itself.
+ tail = reference;
+ tail.queueNext = reference;
notify();
}