From c21797e16a969b3060298cc3dd86c483053bfaa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Sun, 15 Dec 2013 17:49:30 +0200 Subject: [PATCH] Fixed|libdeng2: Protect HighPerformanceTimer for multithreaded access 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. --- doomsday/libdeng2/src/core/highperformancetimer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doomsday/libdeng2/src/core/highperformancetimer.cpp b/doomsday/libdeng2/src/core/highperformancetimer.cpp index c8e72aad2a..39872f0d06 100644 --- a/doomsday/libdeng2/src/core/highperformancetimer.cpp +++ b/doomsday/libdeng2/src/core/highperformancetimer.cpp @@ -18,13 +18,15 @@ #include "de/HighPerformanceTimer" +#include +#include #include 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. @@ -36,6 +38,8 @@ DENG2_PIMPL_NOREF(HighPerformanceTimer) duint64 milliSeconds() { + DENG2_GUARD(this); + int const elapsed = startedAt.elapsed(); duint64 now = duint64(elapsed) + timerOffset;