Browse Source

Modified the posix HighResolutionTimer to cope with being started/stopped from its own callback.

tags/2021-05-28
jules 11 years ago
parent
commit
6773fc2f4f
1 changed files with 22 additions and 7 deletions
  1. +22
    -7
      modules/juce_core/native/juce_posix_SharedCode.h

+ 22
- 7
modules/juce_core/native/juce_posix_SharedCode.h View File

@@ -1146,15 +1146,23 @@ struct HighResolutionTimer::Pimpl
{ {
if (periodMs != newPeriod) if (periodMs != newPeriod)
{ {
stop();
periodMs = newPeriod;
if (thread != pthread_self())
{
stop();
shouldStop = false;
periodMs = newPeriod;
shouldStop = false;
if (pthread_create (&thread, nullptr, timerThread, this) == 0)
setThreadToRealtime (thread, (uint64) newPeriod);
if (pthread_create (&thread, nullptr, timerThread, this) == 0)
setThreadToRealtime (thread, (uint64) newPeriod);
else
jassertfalse;
}
else else
jassertfalse;
{
periodMs = newPeriod;
shouldStop = false;
}
} }
} }
@@ -1191,12 +1199,19 @@ private:
void timerThread() void timerThread()
{ {
Clock clock (periodMs);
int lastPeriod = periodMs;
Clock clock (lastPeriod);
while (! shouldStop) while (! shouldStop)
{ {
clock.wait(); clock.wait();
owner.hiResTimerCallback(); owner.hiResTimerCallback();
if (lastPeriod != periodMs)
{
lastPeriod = periodMs;
clock = Clock (lastPeriod);
}
} }
periodMs = 0; periodMs = 0;


Loading…
Cancel
Save