Queue.mesa
Copyright Ó Xerox Corporation 1987. All rights reserved.
Tim Diebert: April 27, 1987 1:56:28 pm PDT
DIRECTORY
Process USING [DisableTimeout, EnableAborts];
Queue: CEDAR DEFINITIONS
LOCKS queue USING queue: Queue
IMPORTS Process = BEGIN
Constants:
length: CARDINAL = 12;
TYPEs:
Queue: TYPE = REF QueueRep;
QueueRep: TYPE = MONITORED RECORD [
body: ARRAY [FIRST[CARDINAL]..length) OF WORD,
head, tail: CARDINALFIRST[CARDINAL],
nonEmpty: CONDITION];
INLINE ENTRY PROCEDUREs:
Empty: ENTRY PROCEDURE [queue: Queue] RETURNS [empty: BOOLEAN] = INLINE
{ENABLE UNWIND => NULL; RETURN[empty: queue.tail = queue.head]};
Full: ENTRY PROCEDURE [queue: Queue] RETURNS [full: BOOLEAN] = INLINE BEGIN
ENABLE UNWIND => NULL;
RETURN[full: (queue.tail + 1) MOD length = queue.head];
END;
Initialize: ENTRY PROC [queue: Queue] = TRUSTED INLINE BEGIN
ENABLE UNWIND => NULL;
local: QueueRep ← queue^;
Process.DisableTimeout[condition: @local.nonEmpty];
Process.EnableAborts[pCondition: @local.nonEmpty];
RETURN;
END;
Pop: ENTRY PROCEDURE [queue: Queue] RETURNS [item: WORD] = INLINE BEGIN
ENABLE UNWIND => NULL;
IF queue.tail = queue.head THEN WAIT queue.nonEmpty;
item ← queue.body[queue.head];
queue.head ← SUCC[queue.head] MOD length;
RETURN;
END;
Push: ENTRY PROCEDURE [queue: Queue, item: WORD] = INLINE BEGIN
ENABLE UNWIND => NULL;
queue.body[queue.tail] ← item;
queue.tail ← SUCC[queue.tail] MOD length;
NOTIFY queue.nonEmpty;
RETURN;
END;
END.