1 |
/* java.lang.ref.ReferenceQueue |
/* java.lang.ref.ReferenceQueue |
2 |
Copyright (C) 1999 Free Software Foundation, Inc. |
Copyright (C) 1999, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
50 |
* @author Jochen Hoenicke |
* @author Jochen Hoenicke |
51 |
* @see Reference#enqueue() |
* @see Reference#enqueue() |
52 |
*/ |
*/ |
53 |
public class ReferenceQueue |
public class ReferenceQueue<T> |
54 |
{ |
{ |
55 |
/** |
/** |
56 |
* This is a linked list of references. If this is null, the list is |
* This is a linked list of references. If this is null, the list is |
76 |
* @return a reference on the queue, if there is one, |
* @return a reference on the queue, if there is one, |
77 |
* <code>null</code> otherwise. |
* <code>null</code> otherwise. |
78 |
*/ |
*/ |
79 |
public synchronized Reference poll() |
public synchronized Reference<? extends T> poll() |
80 |
{ |
{ |
81 |
return dequeue(); |
return dequeue(); |
82 |
} |
} |
85 |
* This is called by reference to enqueue itself on this queue. |
* This is called by reference to enqueue itself on this queue. |
86 |
* @param ref the reference that should be enqueued. |
* @param ref the reference that should be enqueued. |
87 |
*/ |
*/ |
88 |
synchronized void enqueue(Reference ref) |
synchronized void enqueue(Reference<? extends T> ref) |
89 |
{ |
{ |
90 |
/* last reference will point to itself */ |
/* last reference will point to itself */ |
91 |
ref.nextOnQueue = first == null ? ref : first; |
ref.nextOnQueue = first == null ? ref : first; |
98 |
* Remove a reference from the queue, if there is one. |
* Remove a reference from the queue, if there is one. |
99 |
* @return the first element of the queue, or null if there isn't any. |
* @return the first element of the queue, or null if there isn't any. |
100 |
*/ |
*/ |
101 |
private Reference dequeue() |
private Reference<? extends T> dequeue() |
102 |
{ |
{ |
103 |
if (first == null) |
if (first == null) |
104 |
return null; |
return null; |
105 |
|
|
106 |
Reference result = first; |
Reference<? extends T> result = first; |
107 |
first = (first == first.nextOnQueue) ? null : first.nextOnQueue; |
first = (first == first.nextOnQueue) ? null : first.nextOnQueue; |
108 |
result.nextOnQueue = null; |
result.nextOnQueue = null; |
109 |
return result; |
return result; |
118 |
* <code>null</code> if timeout period expired. |
* <code>null</code> if timeout period expired. |
119 |
* @exception InterruptedException if the wait was interrupted. |
* @exception InterruptedException if the wait was interrupted. |
120 |
*/ |
*/ |
121 |
public synchronized Reference remove(long timeout) |
public synchronized Reference<? extends T> remove(long timeout) |
122 |
throws InterruptedException |
throws InterruptedException |
123 |
{ |
{ |
124 |
if (first == null) |
if (first == null) |
137 |
* @return the reference removed from the queue. |
* @return the reference removed from the queue. |
138 |
* @exception InterruptedException if the wait was interrupted. |
* @exception InterruptedException if the wait was interrupted. |
139 |
*/ |
*/ |
140 |
public Reference remove() |
public Reference<? extends T> remove() |
141 |
throws InterruptedException |
throws InterruptedException |
142 |
{ |
{ |
143 |
return remove(0L); |
return remove(0L); |