FIFOQueueImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Created by: Christian Jacobi, September 16, 1986 10:44:49 am PDT
Last edited by: Christian Jacobi, September 16, 1986 2:13:08 pm PDT
DIRECTORY FIFOQueue;
FIFOQueueImpl:
CEDAR
MONITOR
LOCKS queue USING queue: Queue
EXPORTS FIFOQueue =
BEGIN
Queue: TYPE = FIFOQueue.Queue;
Empty: PUBLIC ERROR = CODE;
Create:
PUBLIC PROC []
RETURNS [queue: Queue] = {
queue ← NEW[FIFOQueue.QueueRec];
};
Include:
PUBLIC
ENTRY
PROC [queue: Queue, value:
REF] = {
ENABLE UNWIND => NULL;
IF queue.front=
NIL
THEN {
queue.front ← queue.tail ← LIST[value];
BROADCAST queue.cond;
}
ELSE {queue.tail.rest ← LIST[value]; queue.tail ← queue.tail.rest}
};
Remove:
PUBLIC ENTRY PROC [queue: Queue]
RETURNS [value:
REF] = {
ENABLE UNWIND => NULL;
IF queue.front=NIL THEN RETURN WITH ERROR Empty;
value ← queue.front.first;
queue.front ← queue.front.rest;
};
RemoveNWait:
PUBLIC ENTRY PROC [queue: Queue]
RETURNS [value:
REF] = {
ENABLE UNWIND => NULL;
WHILE queue.front=
NIL
DO
WAIT queue.cond
ENDLOOP;
value ← queue.front.first;
queue.front ← queue.front.rest;
};
IsEmpty:
PUBLIC PROC [queue: Queue]
RETURNS [
BOOL] = {
RETURN [queue.front=NIL]
};
Flush:
PUBLIC ENTRY PROC [queue: Queue] = {
queue.front ← queue.tail ← NIL;
};
END.