Navigation Menu

Skip to content

Commit

Permalink
Fixed|libcore: Minor data races related to timers
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 53d31a1 commit 01fdc6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion doomsday/libs/core/src/core/timer.cpp
Expand Up @@ -102,6 +102,7 @@ struct TimerScheduler : public Thread, public Lockable

void addPending(Timer &timer)
{
DE_GUARD(this);
const TimeSpan repeatDuration = timer.interval();
pending.push(
Pending{sc::system_clock::now() + sc::microseconds(dint64(repeatDuration * 1.0e6)),
Expand Down Expand Up @@ -145,7 +146,7 @@ DE_PIMPL_NOREF(Timer)
TimeSpan interval = 1.0;
bool isSingleShot = false;
bool isActive = false;
bool isPending = false; // posted but not executed yet
std::atomic_bool isPending{false}; // posted but not executed yet

~Impl()
{
Expand Down
9 changes: 5 additions & 4 deletions doomsday/libs/core/src/data/time.cpp
Expand Up @@ -26,6 +26,7 @@
#include "de/Thread"
#include "de/Writer"

#include <atomic>
#include <ctime>
#include <sstream>

Expand All @@ -37,7 +38,7 @@ static HighPerformanceTimer &highPerfTimer()
return hpt;
}

static TimeSpan currentHighPerfDelta;
static std::atomic<double> currentHighPerfDelta;

duint64 Time::Span::asMicroSeconds() const
{
Expand Down Expand Up @@ -741,17 +742,17 @@ TimeSpan Time::highPerformanceTime() const

Time Time::currentHighPerformanceTime() // static
{
return fromHighPerformanceDelta(currentHighPerfDelta);
return fromHighPerformanceDelta(currentHighPerfDelta.load());
}

void Time::updateCurrentHighPerformanceTime() // static
{
currentHighPerfDelta = highPerfTimer().elapsed();
currentHighPerfDelta.store(highPerfTimer().elapsed());
}

Time::Span Time::currentHighPerformanceDelta()
{
return currentHighPerfDelta;
return currentHighPerfDelta.load();
}

std::ostream &operator<<(std::ostream &os, Time const &t)
Expand Down

0 comments on commit 01fdc6e

Please sign in to comment.