compile and configuration fixes from OSX but useful everywhere
[jack.git] / libjack / time.c
blob6412ea0a5a917032d9d05b87e1986d5bb431a9b0
1 /* -*- mode: c; c-file-style: "bsd"; -*- */
2 /*
3 Copyright (C) 2001-2003 Paul Davis
4 Copyright (C) 2005 Jussi Laako
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <config.h>
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <stdio.h>
27 #ifdef HAVE_STDINT_H
28 #include <stdint.h>
29 #endif
30 #include <string.h>
31 #include <sys/types.h>
32 #include <sys/mman.h>
34 #include <jack/internal.h>
35 #include <jack/jack.h>
36 #include <jack/engine.h>
38 #include <sysdeps/time.h>
39 #include <sysdeps/cycles.h>
41 #include "local.h"
43 const char*
44 jack_clock_source_name (jack_timer_type_t src)
46 switch (src) {
47 case JACK_TIMER_CYCLE_COUNTER:
48 return "cycle counter";
49 case JACK_TIMER_HPET:
50 return "hpet";
51 case JACK_TIMER_SYSTEM_CLOCK:
52 #ifdef HAVE_CLOCK_GETTIME
53 return "system clock via clock_gettime";
54 #else
55 return "system clock via gettimeofday";
56 #endif
59 /* what is wrong with gcc ? */
61 return "unknown";
64 #ifndef HAVE_CLOCK_GETTIME
66 jack_time_t
67 jack_get_microseconds_from_system (void) {
68 jack_time_t jackTime;
69 struct timeval tv;
71 gettimeofday (&tv, NULL);
72 jackTime = (jack_time_t) tv.tv_sec * 1000000 + (jack_time_t) tv.tv_usec;
73 return jackTime;
76 #else
78 jack_time_t
79 jack_get_microseconds_from_system (void) {
80 jack_time_t jackTime;
81 struct timespec time;
83 clock_gettime(CLOCK_MONOTONIC, &time);
84 jackTime = (jack_time_t) time.tv_sec * 1e6 +
85 (jack_time_t) time.tv_nsec / 1e3;
86 return jackTime;
89 #endif /* HAVE_CLOCK_GETTIME */
91 /* everything below here should be system-dependent */
93 #include <sysdeps/time.c>