Browse Source

Made TimeHelpers::lastMSCounterValue atomic

tags/2021-05-28
Tom Poole 8 years ago
parent
commit
f4c7a82ace
1 changed files with 5 additions and 7 deletions
  1. +5
    -7
      modules/juce_core/time/juce_Time.cpp

+ 5
- 7
modules/juce_core/time/juce_Time.cpp View File

@@ -177,7 +177,7 @@ namespace TimeHelpers
+ t.tm_sec;
}
static uint32 lastMSCounterValue = 0;
static Atomic<uint32> lastMSCounterValue { (uint32) 0 };
}
//==============================================================================
@@ -247,12 +247,12 @@ uint32 Time::getMillisecondCounter() noexcept
{
auto now = juce_millisecondsSinceStartup();
if (now < TimeHelpers::lastMSCounterValue)
if (now < TimeHelpers::lastMSCounterValue.get())
{
// in multi-threaded apps this might be called concurrently, so
// make sure that our last counter value only increases and doesn't
// go backwards..
if (now < TimeHelpers::lastMSCounterValue - 1000)
if (now < TimeHelpers::lastMSCounterValue.get() - (uint32) 1000)
TimeHelpers::lastMSCounterValue = now;
}
else
@@ -265,10 +265,8 @@ uint32 Time::getMillisecondCounter() noexcept
uint32 Time::getApproximateMillisecondCounter() noexcept
{
if (TimeHelpers::lastMSCounterValue == 0)
getMillisecondCounter();
return TimeHelpers::lastMSCounterValue;
auto t = TimeHelpers::lastMSCounterValue.get();
return t == 0 ? getMillisecondCounter() : t;
}
void Time::waitForMillisecondCounter (uint32 targetTime) noexcept


Loading…
Cancel
Save