draco: Fix typedef name collision w/MSVC compilers.

Avoid name collisions in winsock header. Always use the DracoTimeval typedef,
but map it to LARGE_INTEGER on Windows and timeval everywhere else.

Fixes https://github.com/google/draco/issues/702
This commit is contained in:
Tom Finegan 2021-05-05 12:17:28 -07:00
parent d09e000868
commit e4103dc39f
2 changed files with 11 additions and 10 deletions

View File

@ -17,31 +17,31 @@
namespace draco { namespace draco {
void DracoTimer::Start() { void DracoTimer::Start() {
#ifdef _WIN32 #ifdef _WIN32
QueryPerformanceCounter(&tv_start); QueryPerformanceCounter(&tv_start_);
#else #else
gettimeofday(&tv_start, nullptr); gettimeofday(&tv_start_, nullptr);
#endif #endif
} }
void DracoTimer::Stop() { void DracoTimer::Stop() {
#ifdef _WIN32 #ifdef _WIN32
QueryPerformanceCounter(&tv_end); QueryPerformanceCounter(&tv_end_);
#else #else
gettimeofday(&tv_end, nullptr); gettimeofday(&tv_end_, nullptr);
#endif #endif
} }
int64_t DracoTimer::GetInMs() { int64_t DracoTimer::GetInMs() {
#ifdef _WIN32 #ifdef _WIN32
LARGE_INTEGER elapsed = {0}; LARGE_INTEGER elapsed = {0};
elapsed.QuadPart = tv_end.QuadPart - tv_start.QuadPart; elapsed.QuadPart = tv_end_.QuadPart - tv_start_.QuadPart;
LARGE_INTEGER frequency = {0}; LARGE_INTEGER frequency = {0};
QueryPerformanceFrequency(&frequency); QueryPerformanceFrequency(&frequency);
return elapsed.QuadPart * 1000 / frequency.QuadPart; return elapsed.QuadPart * 1000 / frequency.QuadPart;
#else #else
const int64_t seconds = (tv_end.tv_sec - tv_start.tv_sec) * 1000; const int64_t seconds = (tv_end_.tv_sec - tv_start_.tv_sec) * 1000;
const int64_t milliseconds = (tv_end.tv_usec - tv_start.tv_usec) / 1000; const int64_t milliseconds = (tv_end_.tv_usec - tv_start_.tv_usec) / 1000;
return seconds + milliseconds; return seconds + milliseconds;
#endif #endif
} }

View File

@ -20,9 +20,10 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
#include <windows.h> #include <windows.h>
typedef LARGE_INTEGER timeval; typedef LARGE_INTEGER DracoTimeVal;
#else #else
#include <sys/time.h> #include <sys/time.h>
typedef timeval DracoTimeVal;
#endif #endif
#include <cinttypes> #include <cinttypes>
@ -39,8 +40,8 @@ class DracoTimer {
int64_t GetInMs(); int64_t GetInMs();
private: private:
timeval tv_start; DracoTimeVal tv_start_;
timeval tv_end; DracoTimeVal tv_end_;
}; };
typedef DracoTimer CycleTimer; typedef DracoTimer CycleTimer;