FreeWRL / FreeX3D 4.3.0
EAIoutQueue.java
1// copyright (c) 1997,1998 stephen f. white
2// Modified for EAI FreeWRL code. John Stewart CRC Canada 1999
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2, or (at your option)
7// any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; see the file COPYING. If not, write to
16// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18package vrml.external.FreeWRLEAI;
19import vrml.external.FreeWRLEAI.EAIMessage;
20
21public class EAIoutQueue {
22 private EAIMessage head;
23 private EAIMessage tail;
24
25 public EAIoutQueue() {
26 head = tail = null;
27 }
28
29 public synchronized void enqueue(EAIMessage msg) {
30 msg.next = head;
31 msg.prev = null;
32 if (head == null) {
33 tail = msg;
34 } else {
35 head.prev = msg;
36 }
37 head = msg;
38 }
39
40 public synchronized EAIMessage dequeue() {
41 if (tail == null) return null;
42 EAIMessage msg = tail;
43 tail = tail.prev;
44 if (tail == null) {
45 head = null;
46 } else {
47 tail.next = null;
48 }
49 msg.prev = msg.next = null;
50 return msg;
51 }
52
53 public boolean isEmpty() {
54 return head == null;
55 }
56}