summaryrefslogtreecommitdiff
path: root/config/os
diff options
context:
space:
mode:
authorjoq <joq@0c269be4-1314-0410-8aa9-9f06e86f4224>2004-04-07 04:52:59 +0000
committerjoq <joq@0c269be4-1314-0410-8aa9-9f06e86f4224>2004-04-07 04:52:59 +0000
commit7d9b71c7ecb5ec08dab973d07b9416977385b861 (patch)
tree7a0e221a6aea0f2d64f28ac721bdd4e331336750 /config/os
parent7cf4d1413d5759d06d7b253c6f20b68d08c07169 (diff)
downloadjack1-7d9b71c7ecb5ec08dab973d07b9416977385b861.tar.gz
[0.97.1] config enhancements
git-svn-id: svn+ssh://jackaudio.org/trunk/jack@682 0c269be4-1314-0410-8aa9-9f06e86f4224
Diffstat (limited to 'config/os')
-rw-r--r--config/os/generic/time.h48
1 files changed, 38 insertions, 10 deletions
diff --git a/config/os/generic/time.h b/config/os/generic/time.h
index 5a7ea49..6082a98 100644
--- a/config/os/generic/time.h
+++ b/config/os/generic/time.h
@@ -1,9 +1,7 @@
/*
- Copyright (C) 2004 Jack O'Quin
+ Copyright (C) 2001-2004 Paul Davis, Tilman Linneweh
- Generic version, overridden by OS-specific defines when available.
- In this case, that is necessary, because the generic version
- hasn't been written, yet.
+ Generic version, overridden by OS-specific definition when needed.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -24,9 +22,9 @@
#ifndef __jack_time_h__
#define __jack_time_h__
+#include <stdio.h>
#include <jack/internal.h>
-
-#error No generic <sysdeps/time.h> available.
+#include <sysdeps/cycles.h>
/* This is a kludge. We need one global instantiation of this
* variable in each address space. So, libjack/client.c declares the
@@ -34,9 +32,39 @@
#define JACK_TIME_GLOBAL_DECL jack_time_t __jack_cpu_mhz
extern JACK_TIME_GLOBAL_DECL;
-/* Need implementations. jack_init_time() should only be called ONCE
- * per process. */
-static inline jack_time_t jack_get_microseconds (void);
-static inline void jack_init_time (void);
+static inline jack_time_t
+jack_get_microseconds (void) {
+ return get_cycles() / __jack_cpu_mhz;
+}
+
+/* This function is inspired by similar code in MPLayer.
+ * It should be quite portable
+ */
+static inline jack_time_t
+jack_get_mhz (void)
+{
+ jack_time_t tsc_start, tsc_end;
+ struct timeval tv_start, tv_end;
+ long usec_delay;
+ jack_time_t mhz;
+
+ tsc_start = get_cycles();
+ gettimeofday(&tv_start, NULL);
+ usleep(100000);
+ tsc_end = get_cycles();
+ gettimeofday(&tv_end, NULL);
+
+ usec_delay = 1000000 * (tv_end.tv_sec - tv_start.tv_sec)
+ + (tv_end.tv_usec - tv_start.tv_usec);
+ mhz = (tsc_end - tsc_start) / usec_delay;
+ return mhz;
+}
+
+/* This should only be called ONCE per process. */
+static inline void
+jack_init_time ()
+{
+ __jack_cpu_mhz = jack_get_mhz ();
+}
#endif /* __jack_time_h__ */