Browse Source

Linux WebBrowserComponent: Fix potential deadlock in destructor

Until this commit it was possible that the message thread got stuck
waiting for the WebBrowserComponent's thread to finish, while the thread
was waiting for the message thread to handle a posted message.
v7.0.9
attila Attila Szarvas 2 years ago
parent
commit
e4a86316ca
1 changed files with 7 additions and 26 deletions
  1. +7
    -26
      modules/juce_gui_extra/native/juce_linux_X11_WebBrowserComponent.cpp

+ 7
- 26
modules/juce_gui_extra/native/juce_linux_X11_WebBrowserComponent.cpp View File

@@ -854,8 +854,6 @@ private:
else if (cmd == "windowCloseRequest") owner.windowCloseRequest();
else if (cmd == "newWindowAttemptingToLoad") owner.newWindowAttemptingToLoad (url);
else if (cmd == "pageLoadHadNetworkError") handlePageLoadHadNetworkError (params);
threadBlocker.signal();
}
void handlePageAboutToLoad (const String& url, const var& inputParams)
@@ -883,35 +881,18 @@ private:
void handleCommand (const String& cmd, const var& params) override
{
threadBlocker.reset();
(new HandleOnMessageThread (this, cmd, params))->post();
MessageManager::callAsync ([liveness = std::weak_ptr<int> (livenessProbe), this, cmd, params]()
{
if (liveness.lock() == nullptr)
return;
// wait until the command has executed on the message thread
// this ensures that Pimpl can never be deleted while the
// message has not been executed yet
threadBlocker.wait (-1);
handleCommandOnMessageThread (cmd, params);
});
}
void receiverHadError() override {}
//==============================================================================
struct HandleOnMessageThread : public CallbackMessage
{
HandleOnMessageThread (Pimpl* pimpl, const String& cmdToUse, const var& params)
: owner (pimpl), cmdToSend (cmdToUse), paramsToSend (params)
{}
void messageCallback() override
{
owner->handleCommandOnMessageThread (cmdToSend, paramsToSend);
}
Pimpl* owner = nullptr;
String cmdToSend;
var paramsToSend;
};
bool webKitIsAvailable = false;
WebBrowserComponent& owner;
@@ -920,7 +901,7 @@ private:
int childProcess = 0, inChannel = 0, outChannel = 0;
int threadControl[2];
std::unique_ptr<XEmbedComponent> xembed;
WaitableEvent threadBlocker;
std::shared_ptr<int> livenessProbe = std::make_shared<int> (0);
std::vector<pollfd> pfds;
};


Loading…
Cancel
Save