Fix stop watch for unix.

This commit is contained in:
Pavel Krajcevski 2012-08-30 17:13:36 -04:00
parent 70674e5665
commit 588f58b237
3 changed files with 12 additions and 5 deletions

View file

@ -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()

View file

@ -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 {

View file

@ -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() {