Timers and Events
Timer: TYPE ~ REF TimerObject;
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.
}.