]> code.citadel.org Git - citadel.git/blob - shaggy/Queue.java
Clarify that we are GPLv2
[citadel.git] / shaggy / Queue.java
1 public class Queue {
2         QElement        head, tail;
3
4         Queue() {
5                 head = tail = null;
6                 }
7
8         public synchronized void append( Object o ) {
9                 if( tail == null )
10                         head = tail = new QElement( o );
11                 else {
12                         tail.next = new QElement( o );
13                         tail = tail.next;
14                         }
15                 notifyAll();
16                 }
17
18         public synchronized Object get() {
19                 try {
20                         while( head == null )
21                                 wait();
22                         } catch( InterruptedException ie ) {
23                                 return null;
24                         }
25
26                 Object          o = head.theData;
27                 head = head.next;
28
29                 if( head == null )
30                         tail = null;
31                 return o;
32                 }
33
34   public boolean empty() {
35     return( head == null );
36   }
37         }
38
39 class QElement {
40         QElement        next;
41         Object          theData;
42
43         QElement( Object o ) {
44                 next = null;
45                 theData = o;
46                 }
47         }
48