The timer package contains a number of routines that assist in
manipulating lists of objects of type
struct TM_Elem
.
TM_Elems (timers) are assigned a timeout value by the user and
inserted in a package-maintained list. The time remaining to
timeout for each timer is kept up to date by the package under user
control. There are routines to remove a timer from its list, to
return an expired timer from a list and to return the next timer to
expire. This specialized package is currently used by the IOMGR
package and by the implementation of RPC2. A timer is used commonly
by inserting a field of type
struct TM_Elem
into a
structure. After inserting the desired timeout value the structure
is inserted into a list, by means of its timer field.
static struct TM_Elem *requests; . . . TM_Init ( & requests); /* Initialize timer list */ . . . for (;;) { TM_Rescan (requests); /* Update the timers */ expired = TM_GetExpired (requests); if (expired == 0) break; . . . process expired element . . . }
void TM_Init( @w < out struct TM_Elem **list > , )
The list to be initialized
ok,
not enough free storage
The specified list will be initialized so that it is an empty timer list. This routine must be called before any other operations are applied to the list. )
void TM_Final( @w < out struct TM_Elem **list > , )
The list to be finalized
ok,
*list was 0 or list was never initialized
Call this routine when you are finished with a timer list and the list is empty. This routine releases any auxiliary storage associated with the list. )
void TM_Insert( in struct TM_Elem *list > , @w < in out struct TM_Elem *elem )
The list into which the element is to be inserted
The element to be initialized and inserted
The element elem is initialized so that the TimeLeft field is equal to the TotalTime field. (The TimeLeft field may be kept current by use of TM_Rescan.) The element is then inserted into the list.
The element elem is initialized so that the TimeLeft field is equal to the TotalTime field. (The TimeLeft field may be kept current by use of TM_Rescan.) The element is then inserted into the list. )
void TM_Rescan( @w < out struct TM_Elem **list > , )
The list to be updated
This routine will update the TimeLeft fields of all timers on list . (This is done by checking the time of day clock in Unix.) This routine returns a count of the number of expired timers on the list. This is the only routine (besides TM_Init that updates the TimeLeft field. )
@Pascall(Tag= < TMGetExpired > , Callname=`TM_GetExpired, Abstract=`Return an expired timer from a list, Parmlist=`@w < in struct TM_Elem *list > , Type=`struct TM_Elem *,
The list to be searched, Text=`The specified list will be searched and a pointer to an expired timer will be returned. 0 is returned if there are no expired timers. An expired timer is one whose TimeLeft field is less than or equal to 0. )
void TM_GetEarliest( @w < out struct TM_Elem **list > , )
The list to be searched
This routine returns a pointer to the timer that will be next to expire -- that with a smallest TimeLeft field. If there are no timers on the list, 0 is returned. )
void TM_eql( in struct timeval *t1, in struct timeval *t2 )
a timeval
Another timeval
This routine returns 0 if and only if t1 and t2 are not equal.