CommTimer.mesa
Copyright Ó 1988, 1991 by Xerox Corporation. All rights reserved.
Demers, October 9, 1990 5:04 pm PDT
DIRECTORY
Rope
;
CommTimer: CEDAR DEFINITIONS ~ {
Timers and Events
Timer: TYPE ~ REF TimerObject;
TimerObject: TYPE;
Event: TYPE ~ RECORD [
ref: REF EventObject,
gen: CARD  -- generation number, guarantees uniqueness
];
nullEvent: Event ~ [NIL, 0];
IsNullEvent: PROC [e: Event] RETURNS [BOOL] ~ INLINE { RETURN[e.ref = NIL] };
EventObject: TYPE;
Timer Manipulation
CreateTimer: PROC [grainSizeMsec: INT, expectedWaitMsec: INT] RETURNS [t: Timer];
Create a timer with the given granularity, optimized for event waits of no more than the expected interval.
DestroyTimer: PROC [t: Timer, doEvents: BOOL ¬ FALSE];
Destroy a timer. It is expensive to drop one on the floor.
If doEvents is TRUE, each pending event goes off as the timer is destroyed.
GrainSizeMsec: PROC [t: Timer] RETURNS [grainSizeMsec: INT];
MsecSinceCreated: PROC [t: Timer] RETURNS [msecSinceCreated: INT];
Event Manipulation
EventProc: TYPE ~ PROC [clientData: REF];
Proc to be called (at high priority) when an event occurs. It is the client's responsibility to ensure that this returns quickly, by doing a FORK and SetPriority if necessary.
ScheduleEvent: PROC [t: Timer, waitMsec: INT, proc: EventProc, clientData: REF ¬ NIL]
RETURNS [e: Event];
Arrange for proc[clientData] to be called at high priority after waitMsec has passed.
CancelEvent: PROC [t: Timer, e: Event];
Cancel a scheduled event. If the event has already occurred this is a no-op.
MsecUntilOccurs: PROC [t: Timer, e: Event] RETURNS [msecUntilOccurs: INT];
Approximate.
Errors
Error: ERROR[codes: LIST OF ATOM, msg: Rope.ROPE];
Failures:
$badGrainSize
$staleEvent
$staleTimer
...
}.