1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-08 04:20:09 +00:00

Tweaked Timer and TimeSliceThread to reduce the frequency of their calls to wait()

This commit is contained in:
jules 2015-10-27 11:49:06 +00:00
parent 6e7fc1249c
commit 0506bc6100
2 changed files with 31 additions and 28 deletions

View file

@ -122,45 +122,50 @@ void TimeSliceThread::run()
{
Time nextClientTime;
int numClients = 0;
{
const ScopedLock sl2 (listLock);
index = clients.size() > 0 ? ((index + 1) % clients.size()) : 0;
numClients = clients.size();
index = numClients > 0 ? ((index + 1) % numClients) : 0;
if (TimeSliceClient* const firstClient = getNextClient (index))
nextClientTime = firstClient->nextCallTime;
}
const Time now (Time::getCurrentTime());
if (nextClientTime > now)
if (numClients > 0)
{
timeToWait = (int) jmin ((int64) 500, (nextClientTime - now).inMilliseconds());
}
else
{
timeToWait = index == 0 ? 1 : 0;
const ScopedLock sl (callbackLock);
const Time now (Time::getCurrentTime());
if (nextClientTime > now)
{
const ScopedLock sl2 (listLock);
clientBeingCalled = getNextClient (index);
timeToWait = (int) jmin ((int64) 500, (nextClientTime - now).inMilliseconds());
}
if (clientBeingCalled != nullptr)
else
{
const int msUntilNextCall = clientBeingCalled->useTimeSlice();
timeToWait = index == 0 ? 1 : 0;
const ScopedLock sl2 (listLock);
const ScopedLock sl (callbackLock);
if (msUntilNextCall >= 0)
clientBeingCalled->nextCallTime = now + RelativeTime::milliseconds (msUntilNextCall);
else
clients.removeFirstMatchingValue (clientBeingCalled);
{
const ScopedLock sl2 (listLock);
clientBeingCalled = getNextClient (index);
}
clientBeingCalled = nullptr;
if (clientBeingCalled != nullptr)
{
const int msUntilNextCall = clientBeingCalled->useTimeSlice();
const ScopedLock sl2 (listLock);
if (msUntilNextCall >= 0)
clientBeingCalled->nextCallTime = now + RelativeTime::milliseconds (msUntilNextCall);
else
clients.removeFirstMatchingValue (clientBeingCalled);
clientBeingCalled = nullptr;
}
}
}
}

View file

@ -55,12 +55,6 @@ public:
{
const uint32 now = Time::getMillisecondCounter();
if (now == lastTime)
{
wait (1);
continue;
}
const int elapsed = (int) (now >= lastTime ? (now - lastTime)
: (std::numeric_limits<uint32>::max() - (lastTime - now)));
lastTime = now;
@ -98,6 +92,10 @@ public:
}
}
}
else
{
wait (1);
}
}
else
{