00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifdef WIN32
00040 #include <mmsystem.h>
00041 #else
00042 #include <sys/types.h>
00043 #include <sys/time.h>
00044 #endif
00045
00046 OSG_BEGIN_NAMESPACE
00047
00048 inline
00049 Time getSystemTime (void)
00050 {
00051 Time time;
00052
00053 #ifdef WIN32
00054 time = Time(timeGetTime()) / 1000.0;
00055 #else
00056 struct timeval tv;
00057 gettimeofday(&tv, 0);
00058 time = Time(tv.tv_usec) / 1000000.0 + Time(tv.tv_sec);
00059 #endif
00060
00061 return time;
00062 }
00063
00064
00065 inline
00066 TimeStamp getTimeStamp(void)
00067 {
00068 #ifdef WIN32
00069 Int64 iCounter;
00070
00071 QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&iCounter));
00072
00073 return static_cast<TimeStamp>(iCounter);
00074 #elif defined(__linux) && defined(__i386)
00075
00076 register uint64_t result;
00077
00078 asm volatile (".byte 0x0f, 0x31" : "=A" (result));
00079 return static_cast<TimeStamp>(result);
00080
00081 #else
00082 return static_cast<TimeStamp>(getSystemTime() * 1000.f);
00083 #endif
00084 }
00085
00086
00087 inline
00088 TimeStamp getTimeStampFreq(void)
00089 {
00090 #ifdef WIN32
00091 Int64 iCounterFreq;
00092
00093 QueryPerformanceFrequency(
00094 reinterpret_cast<LARGE_INTEGER *>(&iCounterFreq));
00095
00096 return static_cast<TimeStamp>(iCounterFreq);
00097
00098 #elif defined(__linux) && defined(__i386)
00099
00100 static Int64 iCounterFreq = 0;
00101
00102 if(iCounterFreq == 0)
00103 {
00104
00105
00106 Time start, end;
00107 Int64 cstart, cend;
00108
00109 cstart = getTimeStamp();
00110 start = getSystemTime();
00111
00112 osgsleep(200);
00113
00114 cend = getTimeStamp();
00115 end = getSystemTime();
00116
00117 iCounterFreq = static_cast<Int64>((cend - cstart) / (end - start));
00118 }
00119 return static_cast<TimeStamp>(iCounterFreq);
00120
00121 #else
00122 return static_cast<TimeStamp>(1000000);
00123 #endif
00124 }
00125
00126 inline
00127 Real64 getTimeStampMsecs(TimeStamp ticks)
00128 {
00129 return ticks * 1000. / getTimeStampFreq();
00130 }
00131
00132 OSG_END_NAMESPACE
00133
00134 #define OSGTIME_INLINE_CVSID "@(#)$Id: $"
00135