JackTime.h

00001 /*
00002 Copyright (C) 2001-2003 Paul Davis
00003 Copyright (C) 2004-2006 Grame
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU Lesser General Public License as published by
00007 the Free Software Foundation; either version 2.1 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public License
00016 along with this program; if not, write to the Free Software 
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 
00019 */
00020 
00021 #ifndef __JackTime__
00022 #define __JackTime__
00023 
00024 #include "types.h"
00025 #include "JackExports.h"
00026 #include <stdio.h>
00027 
00028 #ifdef __cplusplus
00029 extern "C"
00030 {
00031 #endif
00032 
00033 #if defined(__APPLE__)
00034 
00035 #include <mach/mach_time.h>
00036         #include <unistd.h>
00037 
00038     extern double __jack_time_ratio;
00039 
00040     static inline jack_time_t GetMicroSeconds(void) {
00041         return (jack_time_t) (mach_absolute_time () * __jack_time_ratio);
00042     }
00043 
00044     /* This should only be called ONCE per process. */
00045     extern void InitTime();
00046 
00047     static inline void JackSleep(long usec) {
00048         usleep(usec);
00049     }
00050 
00051 #endif
00052 
00053 #ifdef WIN32
00054 
00055     extern EXPORT LARGE_INTEGER _jack_freq;
00056 
00057     extern EXPORT jack_time_t GetMicroSeconds(void) ;
00058 
00059     extern void InitTime();
00060 
00061     static void JackSleep(long usec) {
00062         Sleep(usec / 1000);
00063     }
00064 
00065 #endif
00066 
00067 #ifdef linux
00068 
00069 #include <unistd.h>
00070 
00071     static inline void JackSleep(long usec) {
00072         usleep(usec);
00073     }
00074 
00075 #ifdef GETCYCLE_TIME
00076         #include "cycles.h"
00077     extern jack_time_t __jack_cpu_mhz;
00078     extern jack_time_t GetMhz();
00079     extern void InitTime();
00080     static inline jack_time_t GetMicroSeconds (void) {
00081         return get_cycles() / __jack_cpu_mhz;
00082     }
00083 #else
00084         #include <time.h>
00085     extern void InitTime();
00086     static inline jack_time_t GetMicroSeconds (void) {
00087         struct timespec ts;
00088         clock_gettime(CLOCK_MONOTONIC, &ts);
00089         return (jack_time_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
00090     }
00091 #endif
00092 
00093 #endif
00094 
00095 #ifdef __cplusplus
00096 }
00097 #endif
00098 
00099 
00100 #endif
00101 
00102 
00103 

Generated on Wed Jan 10 11:42:46 2007 for Jackdmp by  doxygen 1.4.5