From 588f58b237189171cf7a73fd0ec191735b075444 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Thu, 30 Aug 2012 17:13:36 -0400 Subject: [PATCH] Fix stop watch for unix. --- Core/CMakeLists.txt | 7 +++++++ Core/src/StopWatchUnix.cpp | 8 ++++---- Core/src/StopWatchWin32.cpp | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 6dd52ac..3464eb8 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -19,6 +19,9 @@ ELSEIF( APPLE ) SET( SOURCES ${SOURCES} "src/StopWatchOSX.cpp" ) ELSE() SET( SOURCES ${SOURCES} "src/StopWatchUnix.cpp" ) + + # Assume compiler is GCC + SET( LINK_FLAGS -lrt ${LINK_FLAGS} ) ENDIF() INCLUDE_DIRECTORIES( ${TexC_SOURCE_DIR}/BPTCEncoder/include ) @@ -50,3 +53,7 @@ TARGET_LINK_LIBRARIES( TexCompCore BPTCEncoder ) IF( Boost_FOUND ) TARGET_LINK_LIBRARIES( TexCompCore ${Boost_LIBRARIES} ) ENDIF() + +IF( NOT WIN32 AND NOT APPLE ) + TARGET_LINK_LIBRARIES( TexCompCore rt ) +ENDIF() diff --git a/Core/src/StopWatchUnix.cpp b/Core/src/StopWatchUnix.cpp index 4f353ba..5e48806 100644 --- a/Core/src/StopWatchUnix.cpp +++ b/Core/src/StopWatchUnix.cpp @@ -23,7 +23,7 @@ StopWatch &StopWatch::operator=(const StopWatch &other) { delete impl; } impl = new StopWatchImpl(); - memcpy(impl, other.impl. sizeof(StopWatchImpl)); + memcpy(impl, other.impl, sizeof(StopWatchImpl)); } StopWatch::~StopWatch() { @@ -36,17 +36,17 @@ StopWatch::StopWatch() : impl(new StopWatchImpl) { void StopWatch::Start() { clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(impl->ts)); - impl->timer = double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec); + impl->timer = double(impl->ts.tv_sec) + 1e-9 * double(impl->ts.tv_nsec); } void StopWatch::Stop() { clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(impl->ts)); - impl->duration = -(impl->timer) + (double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec)); + impl->duration = -(impl->timer) + (double(impl->ts.tv_sec) + 1e-9 * double(impl->ts.tv_nsec)); } void StopWatch::Reset() { impl->timer = impl->duration = 0.0; - memset(impl->ts, 0, sizeof(timespec)); + memset(&(impl->ts), 0, sizeof(timespec)); } double StopWatch::TimeInSeconds() const { diff --git a/Core/src/StopWatchWin32.cpp b/Core/src/StopWatchWin32.cpp index 1937e31..bace45c 100755 --- a/Core/src/StopWatchWin32.cpp +++ b/Core/src/StopWatchWin32.cpp @@ -47,7 +47,7 @@ StopWatch &StopWatch::operator=(const StopWatch &other) { delete impl; } impl = new StopWatchImpl(); - memcpy(impl, other.impl. sizeof(StopWatchImpl)); + memcpy(impl, other.impl, sizeof(StopWatchImpl)); } StopWatch::~StopWatch() {