-- FIFODriver.sak -- last edited by Suzuki: 20-Nov-81 12:47:25 DIRECTORY FIFO: TYPE, Connector: TYPE, Scheduler: TYPE, SimIO: TYPE, WF: TYPE; FIFODriver: MONITOR IMPORTS Connector, FIFO, Scheduler, SimIO, WF = BEGIN Reader: PROC [DataAv: Connector.Handle, DataOut: Connector.Handle, ReadReq: Connector.Handle] = { guardian: PROC = {}; p: PROCESS; p ← FORK guardian[]; {WF.WF0[" Reader started.*n"]; THROUGH [0..50) DO Scheduler.Delay[10]; WHILE NOT (NARROW[Connector.Get[DataAv], REF BOOLEAN]↑ = TRUE) DO Scheduler.StandardDelay[] ENDLOOP; Connector.Put[ReadReq, NEW[BOOLEAN ← TRUE]]; WF.WF1["%u ", NARROW[Connector.Get[DataOut], REF CARDINAL]↑]; Scheduler.Delay[5]; Connector.Put[ReadReq, NEW[BOOLEAN ← FALSE]] ENDLOOP; WF.WF0[" Reader terminated.*n"]; Scheduler.ProcessEnd[]}; [] ← JOIN p}; Writer: PROC [SpaceAv: Connector.Handle, WriteReq: Connector.Handle, DataIn: Connector.Handle] = { guardian: PROC = {}; p: PROCESS; p ← FORK guardian[]; {i: CARDINAL; WF.WF0[" Writer started.*n"]; FOR i IN [0..50) DO Scheduler.Delay[10]; WHILE NOT (NARROW[Connector.Get[SpaceAv], REF BOOLEAN]↑ = TRUE) DO Scheduler.StandardDelay[] ENDLOOP; Connector.Put[DataIn, NEW[CARDINAL ← i]]; Connector.Put[WriteReq, NEW[BOOLEAN ← TRUE]]; WF.WF1["%u- ", i]; Scheduler.Delay[5]; Connector.Put[WriteReq, NEW[BOOLEAN ← FALSE]] ENDLOOP; WF.WF0[" Writer terminated.*n"]; Scheduler.ProcessEnd[]}; [] ← JOIN p}; Start: PROC [Init, ReadReq, WriteReq: Connector.Handle] = { guardian: PROC = {}; p: PROCESS; p ← FORK guardian[]; {Connector.Put[ReadReq, NEW[BOOLEAN ← FALSE]]; Connector.Put[WriteReq, NEW[BOOLEAN ← FALSE]]; Scheduler.Delay[10]; Connector.Put[Init, NEW[BOOLEAN ← TRUE]]; Scheduler.Delay[5]; Connector.Put[Init, NEW[BOOLEAN ← FALSE]]; Scheduler.ProcessEnd[]}; [] ← JOIN p}; SimIO.Start["FIFO.jam"]; {init: Connector.Handle ← Connector.Create[]; write: Connector.Handle ← Connector.Create[]; read: Connector.Handle ← Connector.Create[]; in: Connector.Handle ← Connector.Create[]; space: Connector.Handle ← Connector.Create[]; data: Connector.Handle ← Connector.Create[]; out: Connector.Handle ← Connector.Create[]; fifo: PROCESS ← FORK FIFO.FIFOFunc[size: 100, Init: init, WriteRequest: write, ReadRequest: read, DIn: in, SpaceAv: space, DataAv: data, DOut: out]; reader: PROCESS ← FORK Reader[DataAv: data, DataOut: out, ReadReq: read]; writer: PROCESS ← FORK Writer[SpaceAv: space, WriteReq: write, DataIn: in]; start: PROCESS ← FORK Start[Init: init, ReadReq: read, WriteReq: write]; [] ← JOIN fifo; [] ← JOIN reader; [] ← JOIN writer; [] ← JOIN start}; SimIO.Stop[] END.