00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if defined(_WIN32) && defined(_MSC_VER)
00025 # include <vos/corelibs/vosconfig-vc7.h>
00026 #else
00027 # include <vos/corelibs/vosconfig.h>
00028 #endif
00029
00030 #ifdef HAVE_GETTIMEOFDAY
00031 # ifdef HAVE_SYS_TIME_H
00032 # include <sys/time.h>
00033 # else
00034 # warning Note: According to autoconf, you have gettimeofday(), but not <sys/time.h>. I wonder where gettimeofday() is defined.
00035 # endif
00036 #else
00037 # ifdef WIN32
00038 # include <windows.h>
00039 # else
00040 # error I do not know about time on your system
00041 # endif
00042 #endif
00043
00044 #include <time.h>
00045
00046 #if defined(_WIN32) && defined(_MSC_VER)
00047 # ifdef VOS_EXPORTS
00048 # define VOS_API __declspec(dllexport)
00049 # else
00050 # define VOS_API __declspec(dllimport)
00051 # endif
00052 #else
00053 # define VOS_API
00054 #endif
00055
00056 namespace VOS
00057 {
00058
00059 #ifdef HAVE_GETTIMEOFDAY
00060 VOS_API double getRealTime()
00061 {
00062 double now;
00063
00064 struct timeval tv;
00065 gettimeofday(&tv, 0);
00066 now = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0);
00067
00068 return now;
00069 }
00070 #else
00071 # ifdef WIN32
00072
00073
00074
00075 VOS_API double getRealTime()
00076 {
00077 #if defined(__CYGWIN32__)
00078 # define __int64 long long
00079 #endif
00080
00081 static __int64 Freq = 0;
00082 static __int64 FirstCount = 0;
00083 static double startTime = 0;
00084
00085
00086
00087 if (Freq <= 0)
00088 {
00089 FILETIME ft;
00090 LARGE_INTEGER _100nanosecs;
00091
00092 GetSystemTimeAsFileTime(&ft);
00093
00094 _100nanosecs.LowPart = ft.dwLowDateTime;
00095 _100nanosecs.HighPart = ft.dwHighDateTime;
00096
00097
00098
00099
00100 #if defined(__CYGWIN32__)
00101 _100nanosecs.QuadPart -= 116444736000000000ULL;
00102 #else
00103 _100nanosecs.QuadPart -= 116444736000000000;
00104 #endif
00105 startTime = (_100nanosecs.QuadPart / 10000000.0) + (((_100nanosecs.QuadPart / 10) % 1000000) / 1000000.0);
00106 if(Freq < 0) return startTime;
00107 }
00108
00109
00110 if (Freq == 0)
00111 {
00112
00113 if (!QueryPerformanceFrequency((LARGE_INTEGER*)&Freq))
00114 {
00115
00116 Freq=-1;
00117 return getRealTime();
00118 }
00119
00120 QueryPerformanceCounter((LARGE_INTEGER*)&FirstCount);
00121 }
00122
00123
00124 __int64 Count = 0;
00125 QueryPerformanceCounter((LARGE_INTEGER*)&Count);
00126
00127 return startTime + ((double)(Count-FirstCount))/((double)Freq);
00128 }
00129 #else
00130 #error bad configuration or do not know how to do time on this system
00131 #endif // WIN32
00132 #endif // HAVE_GETTIMEOFDAY_H
00133
00134 VOS_API double getTimer()
00135 {
00136 static double lasttime = 0.0;
00137 double now = getRealTime();
00138 double delta = now - lasttime;
00139
00140 if(delta < 0.0) delta = 0.000001;
00141 lasttime += delta;
00142
00143 return lasttime;
00144 }
00145
00146 }