clock_getres()

Get the resolution of the clock

Synopsis:

#include <time.h>

int clock_getres( clockid_t clock_id, 
                  struct timespec * res );

Arguments:

clock_id
The ID of the clock whose resolution you want to get; one of:
  • CLOCK_REALTIME — the standard POSIX-defined clock. Timers based on this clock wake up the processor if it's in a power-saving mode.
  • CLOCK_SOFTTIME — (a QNX Neutrino extension) this clock is active only when the processor isn't in a power-saving mode. For example, an application using a CLOCK_SOFTTIME timer to sleep wouldn't wake up the processor when the application was due to wake up. This will allow the processor to enter a power-saving mode.

    While the processor isn't in a power-saving mode, CLOCK_SOFTTIME behaves the same as CLOCK_REALTIME.

  • CLOCK_MONOTONIC — this clock always increases at a constant rate and can't be adjusted.

For more information about the different clocks, see Other clock sources in the Clocks, Timers, and Getting a Kick Every So Often of Getting Started with QNX Neutrino.

res
A pointer to a timespec structure in which clock_getres() can store the resolution. The function sets the tv_sec member to 0, and the tv_nsec member to be the resolution of the clock, in nanoseconds.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The clock_getres() function gets the resolution of the clock specified by clock_id and puts it into the buffer pointed to by res.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EFAULT
A fault occurred trying to access the buffers provided.
EINVAL
Invalid clock_id.

Examples:

/*
 * This program prints out the clock resolution.
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main( void )
  {
    struct timespec res;

    if ( clock_getres( CLOCK_REALTIME, &res) == -1 ) {
      perror( "clock get resolution" );
      return EXIT_FAILURE;
    }
    printf( "Resolution is %ld micro seconds.\n",
          res.tv_nsec / 1000 );
    return EXIT_SUCCESS;
  }

Classification:

POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes