Skip to content

Commit

Permalink
Fixed|libdeng2: Protect HighPerformanceTimer for multithreaded access
Browse files Browse the repository at this point in the history
If two threads check the current value of HighPerformanceTimer at
the same time, a race condition could occur. Also, QTime is not
inherently thread-safe.
  • Loading branch information
skyjake committed Dec 15, 2013
1 parent c4f614e commit c21797e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion doomsday/libdeng2/src/core/highperformancetimer.cpp
Expand Up @@ -18,13 +18,15 @@

#include "de/HighPerformanceTimer"

#include <de/Guard>
#include <de/Lockable>
#include <QTime>

namespace de {

static duint32 const WARP_INTERVAL = 12 * 60 * 60 * 1000;

DENG2_PIMPL_NOREF(HighPerformanceTimer)
DENG2_PIMPL_NOREF(HighPerformanceTimer), public Lockable
{
QTime startedAt;
duint64 timerOffset; /// Range extension. QTime only provides a 24h range.
Expand All @@ -36,6 +38,8 @@ DENG2_PIMPL_NOREF(HighPerformanceTimer)

duint64 milliSeconds()
{
DENG2_GUARD(this);

int const elapsed = startedAt.elapsed();
duint64 now = duint64(elapsed) + timerOffset;

Expand Down

0 comments on commit c21797e

Please sign in to comment.