src/share/classes/java/lang/ref/ReferenceQueue.java

Print this page
rev 905 : imported patch ref

*** 49,59 **** static ReferenceQueue NULL = new Null(); static ReferenceQueue ENQUEUED = new Null(); static private class Lock { }; private Lock lock = new Lock(); ! private Reference<? extends T> head = null; private long queueLength = 0; boolean enqueue(Reference<? extends T> r) { /* Called only by Reference class */ synchronized (r) { if (r.queue == ENQUEUED) return false; --- 49,59 ---- static ReferenceQueue NULL = new Null(); static ReferenceQueue ENQUEUED = new Null(); static private class Lock { }; private Lock lock = new Lock(); ! private volatile Reference<? extends T> head = null; private long queueLength = 0; boolean enqueue(Reference<? extends T> r) { /* Called only by Reference class */ synchronized (r) { if (r.queue == ENQUEUED) return false;
*** 93,102 **** --- 93,104 ---- * * @return A reference object, if one was immediately available, * otherwise <code>null</code> */ public Reference<? extends T> poll() { + if (head == null) + return null; synchronized (lock) { return reallyPoll(); } }