1 /* gethrxtime -- get high resolution real time
3 Copyright (C) 2005 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* Written by Paul Eggert. */
25 #include "gethrxtime.h"
29 /* Get the current time, as a count of the number of nanoseconds since
30 an arbitrary epoch (e.g., the system boot time). Prefer a
31 high-resolution clock that is not subject to resetting or
41 return xtime_make (ts.tv_sec, ts.tv_nsec);
45 # if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME
48 if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0)
49 return xtime_make (ts.tv_sec, ts.tv_nsec);
57 return xtime_make (tv.tv_sec, 1000 * tv.tv_usec);
61 /* No monotonically increasing clocks are available; fall back on a
62 clock that might jump backwards, since it's the best we can do. */
66 return xtime_make (ts.tv_sec, ts.tv_nsec);