loolwsd/ChildProcessSession.cpp | 44 ++++++++++++++++++++-------------------- loolwsd/ChildProcessSession.hpp | 6 +++-- loolwsd/LOOLKit.cpp | 12 +++++----- 3 files changed, 32 insertions(+), 30 deletions(-)
New commits: commit ecc35dcdb2bdcba2c4dfbd6e2dd4a76bbaae4d7f Author: Ashod Nakashian <[email protected]> Date: Mon Jan 11 22:57:49 2016 -0500 loolwsd: using recursive_mutex since callbacks invoke public functions Change-Id: Iddcf342cf59c4bd534be52a4b4661bc630f07007 Reviewed-on: https://gerrit.libreoffice.org/21378 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp index ac2ed50..c84650d 100644 --- a/loolwsd/ChildProcessSession.cpp +++ b/loolwsd/ChildProcessSession.cpp @@ -38,7 +38,7 @@ using Poco::ProcessHandle; using Poco::StringTokenizer; using Poco::URI; -std::mutex ChildProcessSession::_mutex; +std::recursive_mutex ChildProcessSession::_mutex; ChildProcessSession::ChildProcessSession(const std::string& id, std::shared_ptr<Poco::Net::WebSocket> ws, @@ -63,7 +63,7 @@ ChildProcessSession::~ChildProcessSession() { Log::info("~ChildProcessSession dtor [" + getName() + "]."); - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -145,7 +145,7 @@ bool ChildProcessSession::_handleInput(const char *buffer, int length) tokens[0] == "saveas"); { - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -233,7 +233,7 @@ bool ChildProcessSession::loadDocument(const char * /*buffer*/, int /*length*/, _loKitDocument = _onLoad(getId(), _jailedFilePath); - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _viewId = _loKitDocument->pClass->getView(_loKitDocument); @@ -274,7 +274,7 @@ void ChildProcessSession::sendFontRendering(const char* /*buffer*/, int /*length return; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -307,7 +307,7 @@ void ChildProcessSession::sendFontRendering(const char* /*buffer*/, int /*length bool ChildProcessSession::getStatus(const char* buffer, int length) { - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -339,7 +339,7 @@ bool ChildProcessSession::getCommandValues(const char* /*buffer*/, int /*length* return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -350,7 +350,7 @@ bool ChildProcessSession::getCommandValues(const char* /*buffer*/, int /*length* bool ChildProcessSession::getPartPageRectangles(const char* /*buffer*/, int /*length*/) { - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -388,7 +388,7 @@ void ChildProcessSession::sendTile(const char* /*buffer*/, int /*length*/, Strin return; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -437,7 +437,7 @@ bool ChildProcessSession::clientZoom(const char* /*buffer*/, int /*length*/, Str return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -471,7 +471,7 @@ bool ChildProcessSession::downloadAs(const char* /*buffer*/, int /*length*/, Str const auto tmpDir = Util::createRandomDir(JailedDocumentRoot); const auto url = JailedDocumentRoot + tmpDir + "/" + name; - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); //TODO: Cleanup the file after downloading. _loKitDocument->pClass->saveAs(_loKitDocument, url.c_str(), @@ -500,7 +500,7 @@ bool ChildProcessSession::getTextSelection(const char* /*buffer*/, int /*length* return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -524,7 +524,7 @@ bool ChildProcessSession::paste(const char* /*buffer*/, int /*length*/, StringTo data = Poco::cat(std::string(" "), tokens.begin() + 2, tokens.end()).substr(strlen("data=")); - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -546,7 +546,7 @@ bool ChildProcessSession::insertFile(const char* /*buffer*/, int /*length*/, Str return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (type == "graphic") { @@ -587,7 +587,7 @@ bool ChildProcessSession::keyEvent(const char* /*buffer*/, int /*length*/, Strin if (keycode == (KEY_CTRL | KEY_W)) return true; - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -617,7 +617,7 @@ bool ChildProcessSession::mouseEvent(const char* /*buffer*/, int /*length*/, Str return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -635,7 +635,7 @@ bool ChildProcessSession::unoCommand(const char* /*buffer*/, int /*length*/, Str return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -672,7 +672,7 @@ bool ChildProcessSession::selectText(const char* /*buffer*/, int /*length*/, Str return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -698,7 +698,7 @@ bool ChildProcessSession::selectGraphic(const char* /*buffer*/, int /*length*/, return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -716,7 +716,7 @@ bool ChildProcessSession::resetSelection(const char* /*buffer*/, int /*length*/, return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -747,7 +747,7 @@ bool ChildProcessSession::saveAs(const char* /*buffer*/, int /*length*/, StringT } } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); @@ -785,7 +785,7 @@ bool ChildProcessSession::setPage(const char* /*buffer*/, int /*length*/, String return false; } - std::unique_lock<std::mutex> lock(_mutex); + std::unique_lock<std::recursive_mutex> lock(_mutex); if (_multiView) _loKitDocument->pClass->setView(_loKitDocument, _viewId); diff --git a/loolwsd/ChildProcessSession.hpp b/loolwsd/ChildProcessSession.hpp index 58eb49e..062e4cf 100644 --- a/loolwsd/ChildProcessSession.hpp +++ b/loolwsd/ChildProcessSession.hpp @@ -52,7 +52,7 @@ public: LibreOfficeKitDocument *getLoKitDocument() const { return _loKitDocument; } - std::unique_lock<std::mutex> getLock() { return std::unique_lock<std::mutex>(_mutex); } + std::unique_lock<std::recursive_mutex> getLock() { return std::unique_lock<std::recursive_mutex>(_mutex); } protected: virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) override; @@ -93,7 +93,9 @@ private: std::function<LibreOfficeKitDocument*(const std::string&, const std::string&)> _onLoad; std::function<void(const std::string&)> _onUnload; - static std::mutex _mutex; + /// Synchronize _loKitDocument acess. + /// This should be inside LoKit. + static std::recursive_mutex _mutex; }; #endif diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 7565556..2fa260d 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -625,11 +625,11 @@ private: /// Load a document (or view) and register callbacks. LibreOfficeKitDocument* onLoad(const std::string& sessionId, const std::string& uri) { - std::unique_lock<std::mutex> lock(_mutex); - Log::info("Session " + sessionId + " is loading. " + std::to_string(_clientViews) + " views loaded."); - const unsigned intSessionId = Util::decodeId(sessionId); + + std::unique_lock<std::mutex> lock(_mutex); + const auto it = _connections.find(intSessionId); if (it == _connections.end() || !it->second) { @@ -678,11 +678,11 @@ private: void onUnload(const std::string& sessionId) { - std::unique_lock<std::mutex> lock(_mutex); - Log::info("Session " + sessionId + " is unloading. " + std::to_string(_clientViews - 1) + " views left."); - const unsigned intSessionId = Util::decodeId(sessionId); + + std::unique_lock<std::mutex> lock(_mutex); + const auto it = _connections.find(intSessionId); if (it == _connections.end() || !it->second) { _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
