// Parallel Computing // // Processor communication queue // // Author Matthew Caryl // Created 23.1.97 package Parallel; public class CommunicationQueue { // // public interface // public CommunicationQueue() { // do nothing } public void enqueue(short b) { if (full()) return; if (first + number < SIZE) queue[first + number] = b; else queue[first + number - SIZE] = b; number++; } public short dequeue() { short t = queue[first]; first++; if (first == SIZE) first = 0; number--; return t; } public short usedSpace() { return number; } public short freeSpace() { return (short) (SIZE - number); } public boolean empty() { return number == 0; } public boolean full() { return number == SIZE; } // // private interface // private static final short SIZE = 8; private final short[] queue = new short[SIZE]; private short first = 0; private short number = 0; }