]>
sourceware.org Git - glibc.git/blob - sysdeps/posix/clock_getres.c
a2d466607e3ff0042bcb4a6dd4bc51238ae9ed7f
1 /* Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include <sys/param.h>
24 #include <libc-internal.h>
27 #if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
28 /* Clock frequency of the processor. */
33 /* Get resolution of clock. */
35 clock_getres (clockid_t clock_id
, struct timespec
*res
)
41 #define HANDLE_REALTIME \
43 long int clk_tck = sysconf (_SC_CLK_TCK); \
45 if (__builtin_expect (clk_tck != -1, 1)) \
47 /* This implementation assumes that the realtime clock has a \
48 resolution higher than 1 second. This is the case for any \
49 reasonable implementation. */ \
51 res->tv_nsec = 1000000000 / clk_tck; \
61 #ifndef HANDLED_REALTIME
65 #endif /* handled REALTIME */
69 if ((clock_id
& ((1 << CLOCK_IDFIELD_SIZE
) - 1))
70 != CLOCK_THREAD_CPUTIME_ID
)
77 #if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
79 case CLOCK_PROCESS_CPUTIME_ID
:
81 if (__builtin_expect (nsec
== 0, 0))
85 /* This can only happen if we haven't initialized the `freq'
86 variable yet. Do this now. We don't have to protect this
87 code against multiple execution since all of them should
88 lead to the same result. */
89 freq
= __get_clockfreq ();
90 if (__builtin_expect (freq
== 0, 0))
91 /* Something went wrong. */
94 nsec
= MAX (UINT64_C (1000000000) / freq
, 1);
97 /* File in the values. The seconds are always zero (unless we
98 have a 1Hz machine). */
This page took 0.039469 seconds and 4 git commands to generate.