Index: src/libchcore/TSimpleTimer.cpp =================================================================== diff -u -N -r4fe995b304ea342b50293f92d3c1992b43b820f7 -ra4635addad389b9e117679437a3e1b64a739ea96 --- src/libchcore/TSimpleTimer.cpp (.../TSimpleTimer.cpp) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/libchcore/TSimpleTimer.cpp (.../TSimpleTimer.cpp) (revision a4635addad389b9e117679437a3e1b64a739ea96) @@ -1,104 +1,104 @@ -// ============================================================================ -// Copyright (C) 2001-2013 by Jozef Starosczyk -// ixen@copyhandler.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License -// (version 2) as published by the Free Software Foundation; -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// ============================================================================ -#include "stdafx.h" -#include "TSimpleTimer.h" -#include "TTimestampProviderTickCount.h" - -namespace chcore -{ - TSimpleTimer::TSimpleTimer(bool bAutostart, const ITimestampProviderPtr& spTimestampProvider) : - m_spTimestampProvider(spTimestampProvider), - m_bStarted(false), - m_ullLastTime(0), - m_ullTotalTime(0) - { - if (!spTimestampProvider) - m_spTimestampProvider = std::make_shared(); - - if (bAutostart) - Start(); - } - - TSimpleTimer::~TSimpleTimer() - { - } - - void TSimpleTimer::Start() - { - if (!m_bStarted) - { - m_bStarted = true; - m_ullLastTime = m_spTimestampProvider->GetCurrentTimestamp(); - } - } - - unsigned long long TSimpleTimer::Stop() - { - if (m_bStarted) - { - Tick(); - m_bStarted = false; - } - - return m_ullTotalTime; - } - - unsigned long long TSimpleTimer::Tick() - { - unsigned long long ullCurrent = m_spTimestampProvider->GetCurrentTimestamp(); - if (m_bStarted) - m_ullTotalTime += ullCurrent - m_ullLastTime; - m_ullLastTime = ullCurrent; - - return ullCurrent; - } - - unsigned long long TSimpleTimer::Checkpoint() - { - if (m_bStarted) - { - Tick(); - unsigned long long ullCurrentTotal = m_ullTotalTime; - m_ullTotalTime = 0; - - return ullCurrentTotal; - } - else - return 0; - } - - void TSimpleTimer::Reset() - { - m_bStarted = false; - m_ullLastTime = 0; - m_ullTotalTime = 0; - } - - void TSimpleTimer::Init(unsigned long long ullTotalTime) - { - Stop(); - m_ullTotalTime = ullTotalTime; - m_ullLastTime = 0; - } - - bool TSimpleTimer::IsRunning() const - { - return m_bStarted; - } -} +// ============================================================================ +// Copyright (C) 2001-2013 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#include "stdafx.h" +#include "TSimpleTimer.h" +#include "TTimestampProviderTickCount.h" + +namespace chcore +{ + TSimpleTimer::TSimpleTimer(bool bAutostart, const ITimestampProviderPtr& spTimestampProvider) : + m_spTimestampProvider(spTimestampProvider), + m_bStarted(false), + m_ullLastTime(0), + m_ullTotalTime(0) + { + if (!spTimestampProvider) + m_spTimestampProvider = std::make_shared(); + + if (bAutostart) + Start(); + } + + TSimpleTimer::~TSimpleTimer() + { + } + + void TSimpleTimer::Start() + { + if (!m_bStarted) + { + m_bStarted = true; + m_ullLastTime = m_spTimestampProvider->GetCurrentTimestamp(); + } + } + + unsigned long long TSimpleTimer::Stop() + { + if (m_bStarted) + { + Tick(); + m_bStarted = false; + } + + return m_ullTotalTime; + } + + unsigned long long TSimpleTimer::Tick() + { + unsigned long long ullCurrent = m_spTimestampProvider->GetCurrentTimestamp(); + if (m_bStarted) + m_ullTotalTime += ullCurrent - m_ullLastTime; + m_ullLastTime = ullCurrent; + + return ullCurrent; + } + + unsigned long long TSimpleTimer::Checkpoint() + { + if (m_bStarted) + { + Tick(); + unsigned long long ullCurrentTotal = m_ullTotalTime; + m_ullTotalTime = 0; + + return ullCurrentTotal; + } + else + return 0; + } + + void TSimpleTimer::Reset() + { + m_bStarted = false; + m_ullLastTime = 0; + m_ullTotalTime = 0; + } + + void TSimpleTimer::Init(unsigned long long ullTotalTime) + { + Stop(); + m_ullTotalTime = ullTotalTime; + m_ullLastTime = 0; + } + + bool TSimpleTimer::IsRunning() const + { + return m_bStarted; + } +}