

\chapter{Timers, Periodic Checks, and Conditions}

This module provides functions that allow users to insert hooks,
i.e. user-supplied functions, that are called by the system at
specified times, or as specific conditions arise.

\function{void CcdCallOnCondition(condnum,fnp,arg)}
\args{int condnum;}
\args{CcdVoidFn fnp;}
\args{void *arg;}

This call instructs the system to call the function indicated by the
function pointer {\tt fnp}, with the specified argument {\tt arg}, when the
condition indicated by {\tt condnum} is raised next. Multiple functions may
be registered for the same condition number. A total of 511
conditions, numbered 1 through 511, are supported.  Currently, users
must make sure that various condition numbers used in a program are
disjoint.  (In the future, we may provide a call to allocate the next
available condition number.)

The system supports a predefined condition, with condition number 1
(CcdPROCESSORIDLE, BUT I AM AM NOT SURE THAT IS EXPORTED TO THE USER
PROGRAM), which is raised by the system when there are no entities
(ready threads, messages for objects, posted handlers, etc.) in the
scheduler's queue.

\function{void CcdRaiseCondition(condNum)}
\args{int condNum;}

When this function is called, it invokes all the functions whose
pointers were registered for the \verb#condNum# via a {\em prior} call
to {\tt CcdCallOnCondition(..)}.  All calls to {\tt
CcdCallOnCondition(..)} {\em during} this function's execution takes
effect only after it returns.  Once a user-registered
function is called, it loses its registration.  So, if users want the
function to be called the next time the same condition arises, they
must register the function again.

\function{void CcdPeriodicallyCall(fnp, arg)}
\args{CcdVoidFn fnp;}
\args{void *arg;}

A function registered through this call is called periodically by the
system's scheduler.  Typically, it would be called every time the
scheduler gets control, such as while switching context to a new
thread or before scheduling a message for an object, or before calling
a posted handler. These functions don't have to be re-registered after
every call, unlike the functions for the "conditions". 

\function{void CcdCallFnAfter(fnp, arg, deltaT)}
\args{CcdVoidFn fnp;}
\args{void *arg;}
\args{unsigned int deltaT;}

This call registers a function via a pointer to it, {\tt fnp},  that will be
called at least {\tt deltaT} milliseconds later. 
The registered function {\tt fnp} is actually called the first time the
scheduler gets control after {\tt deltaT} milliseconds have elapsed. 

