1 /*
2 Copyright (C) 2001-2003 Paul Davis
3 Copyright (C) 2005 Jussi Laako
4 Copyright (C) 2004-2008 Grame
5 Copyright (C) 2018 Greg V
6 
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 
21 */
22 
23 #include "JackConstants.h"
24 #include "JackTime.h"
25 #include "JackTypes.h"
26 #include "JackError.h"
27 
28 #include <time.h>
29 #include <unistd.h>
30 
31 jack_time_t (*_jack_get_microseconds)(void) = 0;
32 
jack_get_microseconds_from_system(void)33 static jack_time_t jack_get_microseconds_from_system (void)
34 {
35 	jack_time_t jackTime;
36 	struct timespec time;
37 
38 	clock_gettime(CLOCK_MONOTONIC, &time);
39 	jackTime = (jack_time_t) time.tv_sec * 1e6 +
40 		(jack_time_t) time.tv_nsec / 1e3;
41 	return jackTime;
42 }
43 
44 
JackSleep(long usec)45 SERVER_EXPORT void JackSleep(long usec)
46 {
47 	usleep(usec);
48 }
49 
InitTime()50 SERVER_EXPORT void InitTime()
51 {
52 	/* nothing to do on a generic system - we use the system clock */
53 }
54 
EndTime()55 SERVER_EXPORT void EndTime()
56 {}
57 
SetClockSource(jack_timer_type_t source)58 void SetClockSource(jack_timer_type_t source)
59 {
60 	jack_log("Clock source : %s", ClockSourceName(source));
61 	_jack_get_microseconds = jack_get_microseconds_from_system;
62 }
63 
ClockSourceName(jack_timer_type_t source)64 const char* ClockSourceName(jack_timer_type_t source)
65 {
66 	return "system clock via clock_gettime";
67 }
68 
GetMicroSeconds()69 SERVER_EXPORT jack_time_t GetMicroSeconds()
70 {
71 	return _jack_get_microseconds();
72 }
73 
jack_get_microseconds()74 SERVER_EXPORT jack_time_t jack_get_microseconds()
75 {
76 	return _jack_get_microseconds();
77 }
78 
79