diff options
author | Narayan Kamath <narayan@google.com> | 2014-05-07 09:06:19 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-05-07 09:06:19 +0000 |
commit | d8eb43c1072f8467ae01ab93944c1032c94c6ccc (patch) | |
tree | 3307a327ff535c19bffbca860d3e03dd0bd7080d | |
parent | db3cbbc355adbe08926881ef86a1e18fa6a475b1 (diff) | |
parent | eb3e5888d4b3c17b5b6e977440178e88ba174f93 (diff) | |
download | libcore-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.java | 21 |
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(); } |