loolwsd/ChildProcessSession.cpp | 2 +- loolwsd/LOOLKit.cpp | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-)
New commits: commit 5130aa214d63831d08f8ae9c746f82fdb1f72e3c Author: Ashod Nakashian <[email protected]> Date: Sun Jan 10 21:55:12 2016 -0500 loolwsd: better locking in Document Change-Id: Ia6cef55201f5505e703026a8461282b5fb79fd85 Reviewed-on: https://gerrit.libreoffice.org/21330 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp index 9424769..883c648 100644 --- a/loolwsd/ChildProcessSession.cpp +++ b/loolwsd/ChildProcessSession.cpp @@ -256,11 +256,11 @@ bool ChildProcessSession::loadDocument(const char * /*buffer*/, int /*length*/, _loKitDocument->pClass->setPart(_loKitDocument, part); } - // Respond by the document status, which has no arguments. if (!getStatus(nullptr, 0)) return false; + Log::info("Loaded session " + getId()); return true; } diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 4750d08..f6fa52f 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -568,6 +568,8 @@ public: void purgeSessions() { + std::unique_lock<std::mutex> lock(_mutex); + for (auto it =_connections.cbegin(); it != _connections.cend(); ) { if (!it->second->isRunning()) @@ -581,7 +583,9 @@ public: bool hasConnections() { - return _connections.size() > 0; + std::unique_lock<std::mutex> lock(_mutex); + + return !_connections.empty(); } private: @@ -619,11 +623,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 unloading. " + std::to_string(_clientViews) + " views loaded."); + 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) { @@ -631,6 +635,8 @@ private: return nullptr; } + lock.unlock(); + if (_loKitDocument == nullptr) { Log::info("Loading new document from URI: [" + uri + "] for session [" + sessionId + "]."); @@ -667,11 +673,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) { @@ -679,6 +685,8 @@ private: return; } + lock.unlock(); + --_clientViews; if (_multiView && _loKitDocument) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
