JackTime.h

00001 /*
00002 Copyright (C) 2001-2003 Paul Davis
00003 Copyright (C) 2004-2008 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         {
00042         return (jack_time_t) (mach_absolute_time () * __jack_time_ratio);
00043     }
00044 
00045     /* This should only be called ONCE per process. */
00046     extern void InitTime();
00047 
00048     static inline void JackSleep(int usec) 
00049         {
00050         usleep(usec);
00051     }
00052 
00053 #endif
00054 
00055 #ifdef WIN32
00056 
00057     extern EXPORT LARGE_INTEGER _jack_freq;
00058 
00059     extern EXPORT jack_time_t GetMicroSeconds(void) ;
00060 
00061     extern void InitTime();
00062 
00063     static void JackSleep(int usec) 
00064         {
00065         Sleep(usec / 1000);
00066     }
00067 
00068 #endif
00069 
00070 #ifdef linux
00071 
00072 #include <unistd.h>
00073 
00074     static inline void JackSleep(long usec) 
00075         {
00076         usleep(usec);
00077     }
00078 
00079 #ifdef GETCYCLE_TIME
00080         #include "cycles.h"
00081     extern jack_time_t __jack_cpu_mhz;
00082     extern jack_time_t GetMhz();
00083     extern void InitTime();
00084     static inline jack_time_t GetMicroSeconds(void) 
00085         {
00086         return get_cycles() / __jack_cpu_mhz;
00087     }
00088 #else
00089         #include <time.h>
00090     extern void InitTime();
00091     static inline jack_time_t GetMicroSeconds(void) 
00092         {
00093         struct timespec ts;
00094         clock_gettime(CLOCK_MONOTONIC, &ts);
00095         return (jack_time_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
00096     }
00097 #endif
00098 
00099 #endif
00100 
00101 #ifdef __cplusplus
00102 }
00103 #endif
00104 
00105 
00106 #endif
00107 
00108 
00109 

Generated on Thu Feb 14 11:16:02 2008 for Jackdmp by  doxygen 1.5.1