TimerImpl.mesa
Last Modified On December 16, 1983 1:30 pm By Paul Rovner
DIRECTORY
BasicTime USING[Pulses, GetClockPulses, PulsesToSeconds],
Timer USING[Seconds];
TimerImpl: MONITOR
LOCKS self USING self: Handle
IMPORTS BasicTime
EXPORTS Timer
= {
TYPEs
Handle: TYPE = REF Object;
Object: PUBLIC TYPE = MONITORED RECORD[
bigBangTime, previousMark: BasicTime.Pulses,
secondsSinceFirstBigBang: Seconds ← 0.0
];
Seconds: TYPE = Timer.Seconds; -- REAL--
PROCEDUREs
Create: PUBLIC PROC RETURNS[Handle] = {
startMark: BasicTime.Pulses = BasicTime.GetClockPulses[];
RETURN[NEW[Object ← [LOCK:, bigBangTime: startMark, previousMark: startMark]]];
};
Read: PUBLIC ENTRY PROC[self: Handle]
RETURNS[time, deltaTime: Seconds] = {
nextMark: BasicTime.Pulses ← BasicTime.GetClockPulses[];
IF BasicTime.PulsesToSeconds[nextMark] - BasicTime.PulsesToSeconds[self.bigBangTime] > 15.0*60.0 -- 15 mins
THEN {self.secondsSinceFirstBigBang ← self.secondsSinceFirstBigBang + (BasicTime.PulsesToSeconds[self.previousMark]-BasicTime.PulsesToSeconds[self.bigBangTime]);
self.bigBangTime ← self.previousMark};
deltaTime ← (BasicTime.PulsesToSeconds[nextMark] - BasicTime.PulsesToSeconds[self.previousMark]);
time ← (BasicTime.PulsesToSeconds[nextMark]-BasicTime.PulsesToSeconds[self.bigBangTime]) + self.secondsSinceFirstBigBang;
self.previousMark ← nextMark;
};
Reset: PUBLIC ENTRY PROC[self: Handle] = {
startMark: BasicTime.Pulses = BasicTime.GetClockPulses[];
self.bigBangTime ← self.previousMark ← startMark;
self.secondsSinceFirstBigBang ← 0.0;
};
}.