Browse Source

Make Application::quit() thread-safe

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
396f5edb07
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 16 additions and 0 deletions
  1. +13
    -0
      dgl/src/ApplicationPrivateData.cpp
  2. +3
    -0
      dgl/src/ApplicationPrivateData.hpp

+ 13
- 0
dgl/src/ApplicationPrivateData.cpp View File

@@ -32,6 +32,7 @@ Application::PrivateData::PrivateData(const bool standalone)
standalone ? PUGL_WORLD_THREADS : 0x0)),
isStandalone(standalone),
isQuitting(false),
isQuittingInNextCycle(false),
isStarting(true),
visibleWindows(0),
windows(),
@@ -92,6 +93,12 @@ void Application::PrivateData::oneWindowClosed() noexcept

void Application::PrivateData::idle(const uint timeoutInMs)
{
if (isQuittingInNextCycle)
{
quit();
isQuittingInNextCycle = false;
}

if (world != nullptr)
{
const double timeoutInSeconds = timeoutInMs != 0
@@ -112,6 +119,12 @@ void Application::PrivateData::quit()
{
DISTRHO_SAFE_ASSERT_RETURN(isStandalone,);

if (! isQuittingInNextCycle)
{
isQuittingInNextCycle = true;
return;
}

isQuitting = true;

#ifndef DPF_TEST_APPLICATION_CPP


+ 3
- 0
dgl/src/ApplicationPrivateData.hpp View File

@@ -39,6 +39,9 @@ struct Application::PrivateData {
/** Whether the applicating is about to quit, or already stopped. Defaults to false. */
bool isQuitting;

/** Helper for safely close everything from main thread. */
bool isQuittingInNextCycle;

/** Whether the applicating is starting up, that is, no windows have been made visible yet. Defaults to true. */
bool isStarting;



Loading…
Cancel
Save