4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #include <pulse/timeval.h>
34 #include <pulsecore/macro.h>
38 pa_usec_t
pa_rtclock_age(const struct timeval
*tv
) {
42 return pa_timeval_diff(pa_rtclock_get(&now
), tv
);
45 struct timeval
*pa_rtclock_get(struct timeval
*tv
) {
46 #ifdef HAVE_CLOCK_GETTIME
47 static int no_monotonic
= 0;
50 /* No locking or atomic ops for no_monotonic here */
53 #ifdef CLOCK_MONOTONIC
54 if (clock_gettime(CLOCK_MONOTONIC
, &ts
) >= 0)
61 pa_assert_se(clock_gettime(CLOCK_REALTIME
, ts
) == 0);
66 tv
->tv_sec
= ts
.tv_sec
;
67 tv
->tv_usec
= ts
.tv_nsec
/ 1000;
71 #else /* HAVE_CLOCK_GETTIME */
73 return pa_gettimeofday(tv
);
78 int pa_rtclock_hrtimer(void) {
79 #ifdef HAVE_CLOCK_GETTIME
82 #ifdef CLOCK_MONOTONIC
83 if (clock_getres(CLOCK_MONOTONIC
, &ts
) >= 0)
84 return ts
.tv_sec
== 0 && ts
.tv_nsec
<= PA_HRTIMER_THRESHOLD_USEC
*1000;
87 pa_assert_se(clock_getres(CLOCK_REALTIME
, &ts
) == 0);
88 return ts
.tv_sec
== 0 && ts
.tv_nsec
<= PA_HRTIMER_THRESHOLD_USEC
*1000;
90 #else /* HAVE_CLOCK_GETTIME */