jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.2KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __JackTime__
  17. #define __JackTime__
  18. #include "types.h"
  19. #include "JackExports.h"
  20. #include <stdio.h>
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. #if defined(__APPLE__)
  26. #include <mach/mach_time.h>
  27. #include <unistd.h>
  28. extern EXPORT double __jack_time_ratio;
  29. static inline jack_time_t GetMicroSeconds(void)
  30. {
  31. return (jack_time_t) (mach_absolute_time () * __jack_time_ratio);
  32. }
  33. /* This should only be called ONCE per process. */
  34. extern void InitTime();
  35. static inline void JackSleep(int usec)
  36. {
  37. usleep(usec);
  38. }
  39. #endif
  40. #ifdef WIN32
  41. extern EXPORT LARGE_INTEGER _jack_freq;
  42. extern EXPORT jack_time_t GetMicroSeconds(void) ;
  43. extern void InitTime();
  44. static void JackSleep(int usec)
  45. {
  46. Sleep(usec / 1000);
  47. }
  48. #endif
  49. #ifdef linux
  50. #include <unistd.h>
  51. static inline void JackSleep(long usec)
  52. {
  53. usleep(usec);
  54. }
  55. #ifdef GETCYCLE_TIME
  56. #include "cycles.h"
  57. extern jack_time_t __jack_cpu_mhz;
  58. extern jack_time_t GetMhz();
  59. extern void InitTime();
  60. static inline jack_time_t GetMicroSeconds(void)
  61. {
  62. return get_cycles() / __jack_cpu_mhz;
  63. }
  64. #else
  65. #include <time.h>
  66. extern void InitTime();
  67. static inline jack_time_t GetMicroSeconds(void)
  68. {
  69. struct timespec ts;
  70. clock_gettime(CLOCK_MONOTONIC, &ts);
  71. return (jack_time_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
  72. }
  73. #endif
  74. #endif
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif