ct_install_clock

The ct_install_clock function installs a callback function to define the tick interval for timeouts.

Prototype:

Ct_clock ct_install_clock( Ct_clock clock_function );

Parameters:

clock_function
A pointer to a clock function (see below), or NULL.

Return Value:

A pointer to the previous clock function.

Discussion:

The ct_install_clock function installs a client-supplied timer function to be used by the timeout mechanism. It returns a pointer to the function that was previously in effect. In most cases you will probably ignore this return value, but it enables you to save the previous function and reinstall it later.

If you pass a NULL parameter, ct_install_clock() installs the default timer function, which is based on the standard clock() function.

A Ct_clock is typedefed in ct.h as a pointer to a function that accepts no parameters and returns a Ct_time by value. The return value should represent the current system time.

A Ct_time is declared in ct.h as the following structure:

typedef struct		/* For timers */
{
	unsigned long tick; /* ticks */
	unsigned long era;  /* cycles of ULONG_MAX + 1 ticks */
} Ct_time;
The tick member represents the smallest interval of time recognized by the timer. It may represent seconds, hundredths of a second, or whatever unit of time is appropriate for the application.

The era member is used for overflow. Increment the era member whenever you increment the tick member past LONG_MAX as defined in limits.h. By this means you can use a Ct_time to represent extremely long intervals. If your application will never run long enough for overflow to be an issue, your timer function can ignore the era member.

Restrictions:

In principle, you can call ct_install_clock at any time. In practice, it normally makes sense to do so only before starting the scheduler. If you install a clock while the scheduler is running, any outstanding timeouts will almost certainly expire at the wrong time.

The ct_install_clock function is available only if you compile Cheap Threads with the CT_TIMEOUT macro defined.


Home