1 /* Copyright (C) 1999, 2000, 2001 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>
28 /* Clock frequency of the processor. */
33 /* Get resolution of clock. */
35 clock_getres (clockid_t clock_id
, struct timespec
*res
)
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
;
59 case CLOCK_PROCESS_CPUTIME_ID
:
60 case CLOCK_THREAD_CPUTIME_ID
:
62 if (__builtin_expect (nsec
== 0, 0))
66 /* This can only happen if we haven't initialized the `freq'
67 variable yet. Do this now. We don't have to protect this
68 code against multiple execution since all of them should
69 lead to the same result. */
70 freq
= __get_clockfreq ();
71 if (__builtin_expect (freq
== 0, 0))
72 /* Something went wrong. */
75 nsec
= MAX (UINT64_C (1000000000) / freq
, 1);
78 /* File in the values. The seconds are always zero (unless we
79 have a 1Hz machine). */