mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Made TimeHelpers::lastMSCounterValue atomic
This commit is contained in:
parent
f85d706131
commit
f4c7a82ace
1 changed files with 5 additions and 7 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue