RoseValueSequencesImpl.Mesa
Last Edited by: Spreitzer, May 17, 1985 11:54:51 am PDT
DIRECTORY Atom, IO, RoseSets, RoseTypes, RoseValueSequences;
RoseValueSequencesImpl:
CEDAR
MONITOR
LOCKS sp WITH sp: SynchPipe
EXPORTS RoseValueSequences
= {
OPEN RoseTypes, RoseSets, RoseValueSequences;
SynchPipe: TYPE = REF SynchPipeRep;
SynchPipeRep:
TYPE =
MONITORED
RECORD [
curAvail: INT ← -1,
curConsumed: INT ← -2,
somethingHappened: CONDITION
];
NumChars: INT = CHAR.LAST.ORD.SUCC - CHAR.FIRST.ORD;
PipeGet:
PROC [self:
STREAM]
RETURNS [c:
CHAR] = {
EntryGet:
ENTRY
PROC [sp: SynchPipe] = {
sp.curConsumed ← sp.curConsumed + 1;
BROADCAST sp.somethingHappened;
DO
SELECT sp.curAvail - sp.curConsumed
FROM
0 => WAIT sp.somethingHappened;
1 => EXIT;
ENDCASE => ERROR IO.Error[Failure, self];
ENDLOOP;
c ← 0C + (sp.curAvail MOD NumChars);
};
sp: SynchPipe ← NARROW[self.streamData];
EntryGet[sp];
};
PipePut:
PROC [self:
STREAM, char:
CHAR] = {
EntryPut:
ENTRY
PROC [sp: SynchPipe] = {
sp.curAvail ← sp.curAvail + 1;
BROADCAST sp.somethingHappened;
DO
SELECT
TRUE
FROM
sp.curAvail = sp.curConsumed => EXIT;
sp.curAvail = sp.curConsumed+1 OR (sp.curAvail=0 AND sp.curConsumed=-2) => WAIT sp.somethingHappened;
ENDCASE => ERROR IO.Error[Failure, self];
ENDLOOP;
};
sp: SynchPipe ← NARROW[self.streamData];
EntryPut[sp];
};
Pipe:
PUBLIC
PROC
RETURNS [p: Producer, c: Consumer] = {
};
}.