Browse Source

Made the logMessage() method in UnitTestsDemo thread-safe

tags/2021-05-28
ed 6 years ago
parent
commit
132295bdb3
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      examples/Utilities/UnitTestsDemo.h

+ 7
- 3
examples/Utilities/UnitTestsDemo.h View File

@@ -171,10 +171,13 @@ private:
void logMessage (const String& message)
{
MessageManagerLock mm (this);
WeakReference<UnitTestsDemo> safeOwner (&owner);
if (mm.lockWasGained()) // this lock may fail if this thread has been told to stop
owner.logMessage (message);
MessageManager::callAsync ([=]
{
if (auto* o = safeOwner.get())
o->logMessage (message);
});
}
void timerCallback() override
@@ -224,5 +227,6 @@ private:
testResultsBox.applyFontToAllText (testResultsBox.getFont());
}
JUCE_DECLARE_WEAK_REFERENCEABLE (UnitTestsDemo)
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UnitTestsDemo)
};

Loading…
Cancel
Save