-- File: QueueLockedTiny.mesa, Last Edit: HGM October 15, 1979 8:04 PM

-- Copyright Xerox Corporation 1979, 1980

DIRECTORY
DriverDefs: FROM "DriverDefs" USING [freeQueueLock, freeQueue],
PupDefs: FROM "PupDefs", -- EXPORTs
BufferDefs: FROM "BufferDefs" USING [
Buffer, PupBuffer, RppBuffer, Queue];

QueueLockedTiny: MONITOR LOCKS DriverDefs.freeQueueLock
IMPORTS DriverDefs
EXPORTS DriverDefs, PupDefs, BufferDefs
SHARES BufferDefs =
BEGIN OPEN DriverDefs,
BufferDefs;

bufferSize: PUBLIC CARDINAL;

EnqueuePup: PUBLIC PROCED
URE [Queue, PupBuffer] = LOOPHOLE[Enqueue];
EnqueueRpp: PUBLIC PROCED
URE [Queue, RppBuffer] = LOOPHOLE[Enqueue];
Enqueue: PUBLIC PROCEDURE [q: Queue, b: Buffer] =
BEGIN
b.next ← NIL;
IF q.first=NIL THEN q.first←b ELSE q.last↑.next←b;
q.last ← b;
b.
queue ← q;
q.length ← q.length+1;
END;

DequeuePup: PUBLIC PROCEDURE [Queu
e] RETURNS [PupBuffer] = LOOPHOLE[Dequeue];
DequeueRpp: PUBLIC PROCEDURE [Queu
e] RETURNS [RppBuffer] = LOOPHOLE[Dequeue];
Dequeue: PUBLIC PROCEDURE [q: Queue] RETURNS [b: Buffer] =
BEGIN
IF (b←q.first)=NIL THEN RETURN;
IF (q.first←q.first.next)=NIL THEN q.last←NIL;
q.length ← q.length-1
;
b.queue ← NIL;
b.next ← NIL;
END;


-- This routine is only used by device dri
vers to get buffers to read things into.
-- NB: b.length is
setup for the size of the buffer, including ALL of the encapsulation. All device drivers must fudge things themsleves unless they use all of the encapsulation field.
GetInputBuffer: PUBLIC ENTRY PROCEDURE RETURNS [b: Buffer] =
BEGIN
b ← Dequeue[@freeQueue];
IF b#NIL THEN b.length ← bufferSize;
END;

END. -- QueueLockedTiny