2
* Copyright (C) 2003-2013 The Music Player Daemon Project
3
* http://www.musicpd.org
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 of the License, or
8
* (at your option) any later version.
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 along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
#elif defined(__APPLE__)
25
#include <mach/mach_time.h>
28
#ifndef CLOCK_MONOTONIC
34
MonotonicClockMS(void)
37
return GetTickCount();
38
#elif defined(__APPLE__) /* OS X does not define CLOCK_MONOTONIC */
39
static mach_timebase_info_data_t base;
41
(void)mach_timebase_info(&base);
43
return (unsigned)((mach_absolute_time() * base.numer)
44
/ (1000000 * base.denom));
45
#elif defined(CLOCK_MONOTONIC)
47
clock_gettime(CLOCK_MONOTONIC, &ts);
48
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
50
/* we have no monotonic clock, fall back to gettimeofday() */
53
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
58
MonotonicClockUS(void)
61
LARGE_INTEGER l_value, l_frequency;
63
if (!QueryPerformanceCounter(&l_value) ||
64
!QueryPerformanceFrequency(&l_frequency))
67
uint64_t value = l_value.QuadPart;
68
uint64_t frequency = l_frequency.QuadPart;
70
if (frequency > 1000000) {
72
value /= frequency / 100;
73
} else if (frequency < 1000000) {
80
#elif defined(__APPLE__) /* OS X does not define CLOCK_MONOTONIC */
81
static mach_timebase_info_data_t base;
83
(void)mach_timebase_info(&base);
85
return ((uint64_t)mach_absolute_time() * (uint64_t)base.numer)
86
/ (1000 * (uint64_t)base.denom);
87
#elif defined(CLOCK_MONOTONIC)
89
clock_gettime(CLOCK_MONOTONIC, &ts);
90
return (uint64_t)ts.tv_sec * 1000000 + (uint64_t)(ts.tv_nsec / 1000);
92
/* we have no monotonic clock, fall back to gettimeofday() */
95
return (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec;