X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Futil%2FQueue.java;fp=src%2Forg%2Fibex%2Futil%2FQueue.java;h=0000000000000000000000000000000000000000;hb=ac84b5a03467c0853c7275105712ece6c71be1f1;hp=91b9b29fdc0dc294338ef16711247d299bb3260b;hpb=3f8aa5300e178e8975b0edc896a5a9d303e7bdf3;p=org.ibex.core.git diff --git a/src/org/ibex/util/Queue.java b/src/org/ibex/util/Queue.java deleted file mode 100644 index 91b9b29..0000000 --- a/src/org/ibex/util/Queue.java +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2003 Adam Megacz all rights reserved. -// -// You may modify, copy, and redistribute this code under the terms of -// the GNU Library Public License version 2.1, with the exception of -// the portion of clause 6a after the semicolon (aka the "obnoxious -// relink clause") - -package org.ibex.util; - -/** A simple synchronized queue, implemented as an array */ -public class Queue { - - public Queue(int initiallength) { vec = new Object[initiallength]; } - - /** The store */ - private Object[] vec; - - /** The index of the first node in the queue */ - private int first = 0; - - /** The number of elements in the queue; INVARAINT: size <= vec.length */ - private int size = 0; - - /** Grow the queue, if needed */ - private void grow(int newlength) { - Object[] newvec = new Object[newlength]; - if (first + size > vec.length) { - System.arraycopy(vec, first, newvec, 0, vec.length - first); - System.arraycopy(vec, 0, newvec, vec.length - first, size - (vec.length - first)); - } else { - System.arraycopy(vec, first, newvec, 0, size); - } - first = 0; - vec = newvec; - } - - /** The number of elements in the queue */ - public int size() { return size; } - - /** Empties the queue */ - public synchronized void flush() { - first = 0; - size = 0; - for(int i=0; i= vec.length) vec[first + size - vec.length] = o; - else vec[first + size] = o; - size++; - if (size == 1) notify(); - } - - /** Remove and return and element from the queue, blocking if empty. */ - public Object remove() { return remove(true); } - - /** Remove and return an element from the queue, blocking if - block is true and the queue is empty. */ - public synchronized Object remove(boolean block) { - - while (size == 0 && block) { - try { wait(); } catch (InterruptedException e) { } - } - - if (!block && size == 0) return null; - Object ret = vec[first]; - first++; - size--; - if (first >= vec.length) first = 0; - return ret; - } - - /** Returns the top element in the queue without removing it */ - public synchronized Object peek() { - if (size == 0) return null; - return vec[first]; - } - -}