Guardian Programmer's Guide

Table Of Contents
Managing Time
Guardian Programmer’s Guide 421922-014
18 - 23
A Sample Long-Range Timer
/* Convert target LCT to GMT */
*target = CONVERTTIMESTAMP(jts_target, LCT_TO_GMT, MY_NODE,
&err);
return err;
}
/*
* Checks if the target has been reached. If not, sets a timer
* for half the remaining interval. Returns 0 when target time
* has been reached, -1 otherwise.
*
* N.B: This function rounds *up* the interval, so when the
* target is reached it might overshoot up to 0.01 second.
* Rounding *down* the interval will produce the opposite
* effect--undershooting up to 0.01 second.
*/
int SetupTimeout(int64 jts_gmt_target)
{
int64 jts_current, interval;
jts_current = JULIANTIMESTAMP(GET_GMT);
/*
* Compute half of the interval, convert it from microseconds
* to centiseconds (0.01 second each), and round up to the
* closest centisecond.
*/
interval = (jts_gmt_target - jts_current) / 2;
interval = (interval + 9999) / 10000;
if (interval <= 0)
return 0;
/*
* The timeout value can be a maximum of (2^31 - 1)
* centiseconds, or about 248 days.
*/
if (interval > MAX_TIMEOUT_CENTISECS)
interval = MAX_TIMEOUT_CENTISECS;
printf("timeout for interval = %u\n\n", (int32) interval);
SIGNALTIMEOUT((int32) interval);
return -1;
}