Browse Source

Added a safety mechanism for pathological cases where user code that repeatedly blocks in a timer callback could get the event loop stuck

tags/2021-05-28
jules 9 years ago
parent
commit
15d746cf6e
1 changed files with 6 additions and 0 deletions
  1. +6
    -0
      modules/juce_events/timers/juce_Timer.cpp

+ 6
- 0
modules/juce_events/timers/juce_Timer.cpp View File

@@ -92,6 +92,9 @@ public:
void callTimers() void callTimers()
{ {
// avoid getting stuck in a loop if a timer callback repeatedly takes too long
const uint32 timeout = Time::getMillisecondCounter() + 100;
const LockType::ScopedLockType sl (lock); const LockType::ScopedLockType sl (lock);
while (firstTimer != nullptr && firstTimer->timerCountdownMs <= 0) while (firstTimer != nullptr && firstTimer->timerCountdownMs <= 0)
@@ -109,6 +112,9 @@ public:
t->timerCallback(); t->timerCallback();
} }
JUCE_CATCH_EXCEPTION JUCE_CATCH_EXCEPTION
if (Time::getMillisecondCounter() > timeout)
break;
} }
callbackArrived.signal(); callbackArrived.signal();


Loading…
Cancel
Save