diff options
Diffstat (limited to 'src/threading.cpp')
| -rw-r--r-- | src/threading.cpp | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/src/threading.cpp b/src/threading.cpp index fc20931..bc1852f 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
| @@ -115,84 +115,6 @@ static void FAIL( char const* funcname, int rc) | |||
| 115 | #endif // win32 build | 115 | #endif // win32 build |
| 116 | 116 | ||
| 117 | 117 | ||
| 118 | /* | ||
| 119 | * Returns millisecond timing (in seconds) for the current time. | ||
| 120 | * | ||
| 121 | * Note: This function should be called once in single-threaded mode in Win32, | ||
| 122 | * to get it initialized. | ||
| 123 | */ | ||
| 124 | time_d now_secs(void) { | ||
| 125 | |||
| 126 | #if defined( PLATFORM_XBOX) || defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC) | ||
| 127 | /* | ||
| 128 | * Windows FILETIME values are "100-nanosecond intervals since | ||
| 129 | * January 1, 1601 (UTC)" (MSDN). Well, we'd want Unix Epoch as | ||
| 130 | * the offset and it seems, so would they: | ||
| 131 | * | ||
| 132 | * <http://msdn.microsoft.com/en-us/library/ms724928(VS.85).aspx> | ||
| 133 | */ | ||
| 134 | SYSTEMTIME st; | ||
| 135 | FILETIME ft; | ||
| 136 | ULARGE_INTEGER uli; | ||
| 137 | static ULARGE_INTEGER uli_epoch; // Jan 1st 1970 0:0:0 | ||
| 138 | |||
| 139 | if (uli_epoch.HighPart==0) { | ||
| 140 | st.wYear= 1970; | ||
| 141 | st.wMonth= 1; // Jan | ||
| 142 | st.wDay= 1; | ||
| 143 | st.wHour= st.wMinute= st.wSecond= st.wMilliseconds= 0; | ||
| 144 | |||
| 145 | if (!SystemTimeToFileTime( &st, &ft )) | ||
| 146 | FAIL( "SystemTimeToFileTime", GetLastError() ); | ||
| 147 | |||
| 148 | uli_epoch.LowPart= ft.dwLowDateTime; | ||
| 149 | uli_epoch.HighPart= ft.dwHighDateTime; | ||
| 150 | } | ||
| 151 | |||
| 152 | GetSystemTime( &st ); // current system date/time in UTC | ||
| 153 | if (!SystemTimeToFileTime( &st, &ft )) | ||
| 154 | FAIL( "SystemTimeToFileTime", GetLastError() ); | ||
| 155 | |||
| 156 | uli.LowPart= ft.dwLowDateTime; | ||
| 157 | uli.HighPart= ft.dwHighDateTime; | ||
| 158 | |||
| 159 | /* 'double' has less accuracy than 64-bit int, but if it were to degrade, | ||
| 160 | * it would do so gracefully. In practice, the integer accuracy is not | ||
| 161 | * of the 100ns class but just 1ms (Windows XP). | ||
| 162 | */ | ||
| 163 | # if 1 | ||
| 164 | // >= 2.0.3 code | ||
| 165 | return (double) ((uli.QuadPart - uli_epoch.QuadPart)/10000) / 1000.0; | ||
| 166 | # elif 0 | ||
| 167 | // fix from Kriss Daniels, see: | ||
| 168 | // <http://luaforge.net/forum/forum.php?thread_id=22704&forum_id=1781> | ||
| 169 | // | ||
| 170 | // "seem to be getting negative numbers from the old version, probably number | ||
| 171 | // conversion clipping, this fixes it and maintains ms resolution" | ||
| 172 | // | ||
| 173 | // This was a bad fix, and caused timer test 5 sec timers to disappear. | ||
| 174 | // --AKa 25-Jan-2009 | ||
| 175 | // | ||
| 176 | return ((double)((signed)((uli.QuadPart/10000) - (uli_epoch.QuadPart/10000)))) / 1000.0; | ||
| 177 | # else | ||
| 178 | // <= 2.0.2 code | ||
| 179 | return (double)(uli.QuadPart - uli_epoch.QuadPart) / 10000000.0; | ||
| 180 | # endif | ||
| 181 | #else // !(defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC)) | ||
| 182 | struct timeval tv; | ||
| 183 | // { | ||
| 184 | // time_t tv_sec; /* seconds since Jan. 1, 1970 */ | ||
| 185 | // suseconds_t tv_usec; /* and microseconds */ | ||
| 186 | // }; | ||
| 187 | |||
| 188 | int rc = gettimeofday(&tv, nullptr /*time zone not used any more (in Linux)*/); | ||
| 189 | assert( rc==0 ); | ||
| 190 | |||
| 191 | return ((double)tv.tv_sec) + ((tv.tv_usec)/1000) / 1000.0; | ||
| 192 | #endif // !(defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC)) | ||
| 193 | } | ||
| 194 | |||
| 195 | |||
| 196 | /*---=== Threading ===---*/ | 118 | /*---=== Threading ===---*/ |
| 197 | 119 | ||
| 198 | //--- | 120 | //--- |
