diff options
author | weidai <weidai11@users.noreply.github.com> | 2006-04-06 21:20:25 +0000 |
---|---|---|
committer | weidai <weidai11@users.noreply.github.com> | 2006-04-06 21:20:25 +0000 |
commit | 6aacd0a0de141d218710374018412cca1893ad9d (patch) | |
tree | 34dba126863f587607debfecab883867f5f2d3dd /hrtimer.cpp | |
parent | 254b0f0d4d307221e0328b8f4e892a9bc0d93765 (diff) | |
download | cryptopp-git-6aacd0a0de141d218710374018412cca1893ad9d.tar.gz |
merge in changes by denis bider and fix compile on gcc 3.4.4 and MSVC 6
Diffstat (limited to 'hrtimer.cpp')
-rw-r--r-- | hrtimer.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/hrtimer.cpp b/hrtimer.cpp index b29f745c..c965ba09 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() |