summaryrefslogtreecommitdiff
path: root/hrtimer.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2006-04-06 21:20:25 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2006-04-06 21:20:25 +0000
commit82c4eb38804e011cfd855bc9e292f7533bfe4c2f (patch)
tree34dba126863f587607debfecab883867f5f2d3dd /hrtimer.cpp
parent4c4b05b70d06e818417f6b4f879183a2f233c91b (diff)
downloadcryptopp-82c4eb38804e011cfd855bc9e292f7533bfe4c2f.tar.gz
merge in changes by denis bider and fix compile on gcc 3.4.4 and MSVC 6
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@219 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'hrtimer.cpp')
-rw-r--r--hrtimer.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/hrtimer.cpp b/hrtimer.cpp
index b29f745..c965ba0 100644
--- a/hrtimer.cpp
+++ b/hrtimer.cpp
@@ -34,7 +34,7 @@ double TimerBase::ConvertTo(word64 t, Unit unit)
void TimerBase::StartTimer()
{
- m_start = GetCurrentTimerValue();
+ m_last = m_start = GetCurrentTimerValue();
m_started = true;
}
@@ -42,13 +42,17 @@ double TimerBase::ElapsedTimeAsDouble()
{
if (m_stuckAtZero)
return 0;
- else if (m_started)
- return ConvertTo(GetCurrentTimerValue() - m_start, m_timerUnit);
- else
+
+ if (m_started)
{
- StartTimer();
- return 0;
+ word64 now = GetCurrentTimerValue();
+ if (m_last < now) // protect against OS bugs where time goes backwards
+ m_last = now;
+ return ConvertTo(m_last - m_start, m_timerUnit);
}
+
+ StartTimer();
+ return 0;
}
unsigned long TimerBase::ElapsedTime()