if you are only looking for time intervals why are you calling the wall clock function?
Look into using the alarm() function. From the man page -
NAME alarm - set an alarm clock for delivery of a signal
SYNOPSIS #include
unsigned int alarm(unsigned int seconds);
DESCRIPTION alarm arranges for a SIGALRM signal to be delivered to the process in seconds seconds.
If seconds is zero, no new alarm is scheduled.
In any event any previously set alarm is cancelled.
RETURN VALUE alarm returns the number of seconds remaining until any previously scheduled alarm was due to be delivered, or zero if there was no previ- ously scheduled alarm.
So there is NO interference from changing clock time, no maintenance of internal counters. Just process the SIGALRM signal. This could be as easy as setting a flag to be checked in your main loop/thread.
I'm really surprised no one else mentioned this solution. And if you are working in a Microsoft OS, check for something similar.
Ed.
NOTE: Dan's comments probably refer to low level drivers or hard realtime applications which usually need to proceess on those shorter time intervals and have available those special functions. (Or access to actual hardware timers.)