High-resolution timers
QNX SDP8.0Programmer's GuideDeveloper
You can use timer tolerance to request a high-resolution timer.
After creating a timer by calling timer_create(), you can request a high-resolution timer by specifying the TIMER_TOLERANCE flag, along with a time value between zero and the current tick size, when calling timer_settime(). Then you can call timer_settime() again (without TIMER_TOLERANCE) to set the expiration time and arm the timer.
For this kind of timer, the timer hardware gets programmed to generate an interrupt as close to the elapse of the specified delay time as the hardware and OS can support. As this may cause extra hardware interrupts, you need to have the PROCMGR_AID_HIGH_RESOLUTION_TIMER ability enabled.
Here's an example of setting up a high-resolution timer:
struct sigevent event;
timer_t timerId;
struct itimerspec newTimerTolerance, newTimerSpec;
int rc;
SIGEV_SIGNAL_INIT(&event, SIGUSR1);
rc = timer_create(CLOCK_MONOTONIC, &event, &timerId);
if (rc == -1) {
// Handle the error
}
// Set the tolerance on the timer first because
// setting the time activates the timer.
memset(&newTimerTolerance, 0, sizeof(newTimerTolerance));
newTimerTolerance.it_value.tv_nsec = 1;
rc = timer_settime(timerId, TIMER_TOLERANCE, &newTimerTolerance, NULL);
if (rc == -1) {
// Handle the error
}
// Fire the timer every 2.5 ms
memset(&newTimerSpec, 0, sizeof(newTimerSpec));
newTimerSpec.it_value.tv_nsec = 2500*1000;
newTimerSpec.it_interval.tv_nsec = 2500*1000;
rc = timer_settime(timerId, 0, &newTimerSpec, NULL);
if (rc == -1) {
// Handle the error
}
Page updated: