-- File: DispatcherHot.mesa, Last Edit: HGM October 15, 1979 7:44 PM
-- Copyright Xerox Corporation 1979, 1980
DIRECTORY
DriverDefs: FROM "DriverDefs" USING [
pupRouter, DummyInputer,
doDebug, Network],
BufferDefs: FROM "BufferDefs" USING [Buffer, Dequeue, QueueObject];
DispatcherHot: MONITOR LOCKS dispatcherLock
IMPORTS DriverDefs, BufferDefs
EXPORTS DriverDefs
SHARES BufferDefs =
BEGIN
-- SemiPublic things needed by DispatcherLocked and DispatcherCold
dispatcherPleaseDie: PUBLIC BOOLEAN;
dispatcherLock: PUBLIC MONITORLOCK;
dispatcherReady: PUBLIC CONDITION;
globalInputQueue: PUBLIC BufferDefs.QueueObject;
globalOutputQueue: PUBLIC BufferDefs.QueueObject;
Buffer: TYPE = BufferDefs.Buffer;
MainDispatcher: PUBLIC PROCEDURE =
BEGIN
b: Buffer;
network: DriverDefs.Network;
UNTIL dispatcherPleaseDie DO
WHILE globalOutputQueue.length#0 DO -- give back free buffers first
b ← GrabOutputBuffer[];
IF b.allNets THEN SendToNextNetwork[b]
ELSE b.requeueProcedure[b];
ENDLOOP;
IF globalInputQueue.length#0 THEN
BEGIN
b ← GrabInputBuffer[];
network ← b.network;
SELECT network.decapsulateBuffer[b] FROM
pup, rpp =>
BEGIN
IF DriverDefs.doDebug THEN b.type ← pup;
DriverDefs.pupRouter.input[b];
LOOP;
END;
ENDCASE => DriverDefs.DummyInputer[b];
END;
Wait[];
ENDLOOP;
END;
Wait: ENTRY PROCEDURE = INLINE
BEGIN
IF globalInputQueue.length#0 OR globalOutputQueue.length#0 THEN RETURN;
WAIT dispatcherReady;
END;
GrabOutputBuffer: ENTRY PROCEDURE RETURNS [b: Buffer] = INLINE
BEGIN
b ← BufferDefs.Dequeue[@globalOutputQueue];
END;
GrabInputBuffer: ENTRY PROCEDURE RETURNS [b: Buffer] = INLINE
BEGIN
b ← BufferDefs.Dequeue[@globalInputQueue];
END;
SendToNextNetwork: PROCEDURE [b: Buffer] =
BEGIN
network: DriverDefs.Network ← b.network;
b.network ← network ← network.next;
IF network=NIL THEN
BEGIN
b.allNets ← FALSE; -- this is where it gets turned off
b.requeueProcedure[b];
RETURN;
END;
SELECT b.type FROM
pup, rpp =>
BEGIN
DriverDefs.pupRouter.broadcast[b];
END;
ENDCASE => b.requeueProcedure[b]; -- don’t know how to encapsulate
END;
-- initialization
END. -- DispatcherHot module