예제 #1
0
/* High resolution monotonic clock, falling back to the realtime clock
   if the target does not support such a clock.

   Arguments:
   secs     - OUTPUT, seconds
   fracsecs - OUTPUT, fractional seconds, units given by tk argument
   tk       - OUTPUT, clock resolution [counts/sec]

   If the target supports a monotonic clock, the OUTPUT arguments
   represent a monotonically incrementing clock starting from some
   unspecified time in the past.

   If a monotonic clock is not available, falls back to the realtime
   clock which is not monotonic.

   Return value: 0 for success, -1 for error. In case of error, errno
   is set.
*/
static int
gf_gettime_mono (time_t * secs, long * fracsecs, long * tck)
{
  int err;
#ifdef HAVE_CLOCK_GETTIME
  struct timespec ts;
  *tck = 1000000000;
  err = clock_gettime (GF_CLOCK_MONOTONIC, &ts);
  *secs = ts.tv_sec;
  *fracsecs = ts.tv_nsec;
  return err;
#else
#if SUPPORTS_WEAKREF && defined(HAVE_CLOCK_GETTIME_LIBRT)
  if (weak_gettime)
    {
      struct timespec ts;
      *tck = 1000000000;
      err = weak_gettime (GF_CLOCK_MONOTONIC, &ts);
      *secs = ts.tv_sec;
      *fracsecs = ts.tv_nsec;
      return err;
    }
#endif
  *tck = 1000000;
  err = gf_gettime (secs, fracsecs);
  return err;
#endif
}
예제 #2
0
/* High resolution monotonic clock, falling back to the realtime clock
   if the target does not support such a clock.

   Arguments:
   secs     - OUTPUT, seconds
   nanosecs - OUTPUT, nanoseconds
   tk       - OUTPUT, clock resolution [counts/sec]

   If the target supports a monotonic clock, the OUTPUT arguments
   represent a monotonically incrementing clock starting from some
   unspecified time in the past.

   If a monotonic clock is not available, falls back to the realtime
   clock which is not monotonic.

   Return value: 0 for success, -1 for error. In case of error, errno
   is set.
*/
static int
gf_gettime_mono (time_t * secs, long * nanosecs, long * tck)
{
  int err;
#ifdef HAVE_CLOCK_GETTIME
  struct timespec ts;
  *tck = 1000000000;
  err = clock_gettime (GF_CLOCK_MONOTONIC, &ts);
  *secs = ts.tv_sec;
  *nanosecs = ts.tv_nsec;
  return err;
#else
#if defined(HAVE_CLOCK_GETTIME_LIBRT) && SUPPORTS_WEAK && GTHREAD_USE_WEAK
  if (weak_gettime)
    {
      struct timespec ts;
      *tck = 1000000000;
      err = weak_gettime (GF_CLOCK_MONOTONIC, &ts);
      *secs = ts.tv_sec;
      *nanosecs = ts.tv_nsec;
      return err;
    }
#endif
  *tck = 1000000;
  err = gf_gettime (secs, nanosecs);
  *nanosecs *= 1000;
  return err;
#endif
}
예제 #3
0
파일: pr59063-2.c 프로젝트: 0day-ci/gcc
int main() {
  if (!clock_gettime)
    return 0;
  struct timespec ts;
  return weak_gettime(CLOCK_MONOTONIC, &ts);
}