| Updated: October 28, 2024 | 
Get information about a timer
#include <sys/neutrino.h>
int TimerInfo( pid_t pid,
               timer_t id,
               int flags,
               struct _timer_info* info );
int TimerInfo_r( pid_t pid,
                 timer_t id,
                 int flags,
                 struct _timer_info* info );
You can pass NULL for this argument if the only bit set in flags is _NTO_TIMER_RESET_OVERRUNS.
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
These kernel calls get information about a previously created timer specified by id, and store the information in the buffer pointed to by info.
The TimerInfo() and TimerInfo_r() functions are identical except in the way they indicate errors. See the Returns section for details.
struct _timer_info
The _timer_info structure pointed to by info contains at least these members:
For more information, see the description of TimerCreate().
Blocking states
These calls don't block.
The ID of the timer that the information is for. If an error occurs:
This program creates a timer and then gets information about it. The arguments are the timer's tolerance, the process's default tolerance, and a flag that indicates whether or not to use the process's default tolerance. For more information, see Tolerant and high-resolution timers in the Understanding the Microkernel's Concept of Time chapter of the QNX Neutrino Programmer's Guide.
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/neutrino.h>
#include <sys/procmgr.h>
int main (int argc, char **argv)
{
        struct sigevent event;
        timer_t timerId;
        int tolerance = 0;
        struct itimerspec newTimerTolerance, newTimerSpec;
        int rc;
        struct _timer_info tinfo;
        struct _clockperiod period;
        int precise = 0, not_used = 0;
        uint64_t p_tolerance = 0;
        if (argc > 1) {
          tolerance = atoi (argv[1]);
        }
        if (argc > 2) {
          p_tolerance = atoi (argv[2]);
        }
        if (argc > 3) {
          precise = atoi (argv[3]);
        }
        // Set the process's default tolerance if it's nonzero.
        if (p_tolerance != 0) {
           rc = procmgr_timer_tolerance ( 0, &p_tolerance, NULL);
           if (rc == -1)
           {
              perror ("procmgr_timer_tolerance");
              return EXIT_FAILURE;
           }
        }
        event.sigev_notify = SIGEV_SIGNAL;
        event.sigev_signo = SIGUSR1;
        // Create a timer.
        rc = timer_create(CLOCK_MONOTONIC, &event, &timerId);
        if (rc == -1)
        {
          perror ("timer_create()");
          return EXIT_FAILURE;
        }
        // Set the tolerance on the timer first because
        // setting the time activates the timer.
        memset(&newTimerTolerance, 0, sizeof(newTimerTolerance));
        newTimerTolerance.it_value.tv_sec = 0;
        newTimerTolerance.it_value.tv_nsec = tolerance;
        newTimerTolerance.it_interval.tv_sec  = 0;
        newTimerTolerance.it_interval.tv_nsec = 0;
        rc = timer_settime(timerId, TIMER_TOLERANCE, &newTimerTolerance, NULL);
        if (rc == -1)
        {
          perror ("timer_settime() tolerance");
          return EXIT_FAILURE;
        }
        memset(&newTimerSpec, 0, sizeof(newTimerSpec));
        newTimerSpec.it_value.tv_sec =  5;
        newTimerSpec.it_value.tv_nsec = 5000;
        newTimerSpec.it_interval.tv_sec  = 0;
        newTimerSpec.it_interval.tv_nsec = 0;
        rc = timer_settime(timerId, precise ? TIMER_PRECISE : 0, &newTimerSpec, NULL);
        if (rc == -1)
        {
          perror ("timer_settime() time");
          return EXIT_FAILURE;
        }
        // Get the clock period.
        rc = ClockPeriod (CLOCK_MONOTONIC, NULL, &period, not_used);
        if (rc == -1)
        {
          perror ("ClockPeriod()");
          return EXIT_FAILURE;
        }
        printf ("Clock period: %d ns\n\n", period.nsec);
        // Get information about the timer.
        memset(&tinfo, 0, sizeof(struct _timer_info));
        rc = TimerInfo ( getpid(), timerId, _NTO_TI_REPORT_TOLERANCE, &tinfo);
        if (rc == -1)
        {
          perror ("TimerInfo()");
          return EXIT_FAILURE;
        }
        printf ("Timer information:\n");
        printf ("   Thread ID: %d\n", tinfo.tid);
        switch (tinfo.clockid) {
        case CLOCK_MONOTONIC:
          printf ("   CLOCK_MONOTONIC\n");
          break;
        case CLOCK_REALTIME:
          printf ("   CLOCK_REALTIME\n");
          break;
        case CLOCK_SOFTTIME:
          printf ("   CLOCK_SOFTTIME\n");
          break;
        }
        printf ("   Overruns: %d\n", tinfo.overruns);
        printf ("   Start time: %ld ns; interval: %ld ns\n", tinfo.itime.nsec,
                tinfo.itime.interval_nsec);
        printf ("   Remaining : %ld ns\n", tinfo.otime.nsec);
        if (tinfo.flags &_NTO_TI_ABSOLUTE) {
          printf ("   ABSOLUTE\n");
        } else {
          printf ("   Relative\n");
        }
        if (tinfo.flags &_NTO_TI_ACTIVE) {
          printf ("   ACTIVE\n");
        }
        if (tinfo.flags &_NTO_TI_EXPIRED) {
          printf ("   EXPIRED\n");
        }
        if (tinfo.flags &_NTO_TI_PRECISE) {
          printf ("   PRECISE\n");
        }
        if (tinfo.flags &_NTO_TI_PROCESS_TOLERANT) {
          printf ("   PROCESS_TOLERANT: %ld ns.\n", p_tolerance);
        }
        if (tinfo.flags &_NTO_TI_TARGET_PROCESS) {
          printf ("   TARGET_PROCESS\n");
        }
        if (tinfo.flags &_NTO_TI_TOD_BASED) {
          printf ("   TOD_BASED\n");
        }
        if (tinfo.flags &_NTO_TI_TOLERANT) {
           printf ("   TOLERANT");
           tolerance = tinfo.otime.interval_nsec;
           if ((tolerance > 0) && (tolerance < period.nsec)) {
              printf (" (high-resolution): %d ns.\n", tolerance);
           } else {
              printf (": %d ns.\n", tolerance);
           }
        }
        return EXIT_SUCCESS;
}
| Safety: | |
|---|---|
| Cancellation point | No | 
| Interrupt handler | No | 
| Signal handler | Yes | 
| Thread | Yes |