loolwsd/DocumentBroker.cpp | 39 ++++++++++++++++++++------------------- loolwsd/DocumentBroker.hpp | 16 +++++++--------- loolwsd/LOOLWSD.cpp | 9 +++++---- 3 files changed, 32 insertions(+), 32 deletions(-)
New commits: commit 22fb71c6729cb9139714054bf7096619c3c0aa1e Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sat Oct 8 10:31:35 2016 -0400 loolwsd: cleanup lastEditableSession flag in DocumentBroker Change-Id: Iab3a226e3ff089c6bdab264d6f1b1d639bcf3b37 Reviewed-on: https://gerrit.libreoffice.org/29630 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp index d6aba21..896e7e4 100644 --- a/loolwsd/DocumentBroker.cpp +++ b/loolwsd/DocumentBroker.cpp @@ -109,12 +109,12 @@ DocumentBroker::DocumentBroker() : _lastSaveTime(std::chrono::steady_clock::now()), _markToDestroy(true), _lastEditableSession(true), + _isLoaded(false), + _isModified(false), _cursorPosX(0), _cursorPosY(0), _cursorWidth(0), _cursorHeight(0), - _isLoaded(false), - _isModified(false), _mutex(), _saveMutex(), _tileVersion(0) @@ -134,12 +134,12 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic, _lastSaveTime(std::chrono::steady_clock::now()), _markToDestroy(false), _lastEditableSession(false), + _isLoaded(false), + _isModified(false), _cursorPosX(0), _cursorPosY(0), _cursorWidth(0), _cursorHeight(0), - _isLoaded(false), - _isModified(false), _mutex(), _saveMutex(), _tileVersion(0) @@ -244,7 +244,7 @@ bool DocumentBroker::save(bool success, const std::string& result) // If we aren't destroying the last editable session just yet, and the file // timestamp hasn't changed, skip saving. const auto newFileModifiedTime = Poco::File(_storage->getLocalRootPath()).getLastModified(); - if (!isLastEditableSession() && newFileModifiedTime == _lastFileModifiedTime) + if (!_lastEditableSession && newFileModifiedTime == _lastFileModifiedTime) { // Nothing to do. Log::debug() << "Skipping unnecessary saving to URI [" << uri @@ -409,7 +409,7 @@ size_t DocumentBroker::addSession(std::shared_ptr<ClientSession>& session) } // Below values are recalculated when startDestroy() is called (before destroying the - // document). It is safe to reset their values to their defaults whenever a new session is added + // document). It is safe to reset their values to their defaults whenever a new session is added. _lastEditableSession = false; _markToDestroy = false; @@ -683,31 +683,32 @@ void DocumentBroker::handleTileCombinedResponse(const std::vector<char>& payload } } -void DocumentBroker::startDestroy(const std::string& id) +bool DocumentBroker::startDestroy(const std::string& id) { std::unique_lock<std::mutex> lock(_mutex); - auto currentSession = _sessions.find(id); + const auto currentSession = _sessions.find(id); assert(currentSession != _sessions.end()); - // Check if session which is being destroyed is last non-readonly session - bool lastEditableSession = !currentSession->second->isReadOnly(); - for (auto& it: _sessions) + // Check if the session being destroyed is the last non-readonly session or not. + _lastEditableSession = !currentSession->second->isReadOnly(); + if (_lastEditableSession && !_sessions.empty()) { - if (it.second->getId() == id) - continue; - - if (!it.second->isReadOnly()) + for (const auto& it: _sessions) { - lastEditableSession = false; + if (it.second->getId() != id && + !it.second->isReadOnly()) + { + // Found another editable. + _lastEditableSession = false; + break; + } } } - // Last editable session going away - _lastEditableSession = lastEditableSession; - // Last view going away, can destroy. _markToDestroy = (_sessions.size() <= 1); + return _lastEditableSession; } void DocumentBroker::setModified(const bool value) diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp index 16008f4..4909e34 100644 --- a/loolwsd/DocumentBroker.hpp +++ b/loolwsd/DocumentBroker.hpp @@ -217,18 +217,16 @@ public: const std::shared_ptr<ClientSession>& session); void handleTileCombinedRequest(TileCombined& tileCombined, const std::shared_ptr<ClientSession>& session); - void cancelTileRequests(const std::shared_ptr<ClientSession>& session); - void handleTileResponse(const std::vector<char>& payload); void handleTileCombinedResponse(const std::vector<char>& payload); - // Called before destroying any session - // This method calculates and sets important states of - // session being destroyed. - void startDestroy(const std::string& id); + /// Called before destroying any session. + /// This method calculates and sets important states of + /// session being destroyed. Returns true if session id + /// is the last editable session. + bool startDestroy(const std::string& id); bool isMarkedToDestroy() const { return _markToDestroy; } - bool isLastEditableSession() const { return _lastEditableSession; } bool handleInput(const std::vector<char>& payload); @@ -256,12 +254,12 @@ private: std::unique_ptr<TileCache> _tileCache; std::atomic<bool> _markToDestroy; std::atomic<bool> _lastEditableSession; + std::atomic<bool> _isLoaded; + std::atomic<bool> _isModified; int _cursorPosX; int _cursorPosY; int _cursorWidth; int _cursorHeight; - bool _isLoaded; - bool _isModified; mutable std::mutex _mutex; std::condition_variable _saveCV; std::mutex _saveMutex; diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index d11b724..1889987 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -801,7 +801,7 @@ private: Util::checkDiskSpaceOnRegisteredFileSystems(); - // Let messages flow + // Let messages flow. IoUtil::SocketProcessor(ws, [&session](const std::vector<char>& payload) { @@ -810,16 +810,17 @@ private: [&session]() { session->closeFrame(); }, []() { return !!TerminationFlag; }); + // Connection terminated. Destroy session. { std::unique_lock<std::mutex> docBrokersLock(docBrokersMutex); - // We cannot destroy it, before save, if this is the last session + // We cannot destroy it, before save, if this is the last session. // Otherwise, we may end up removing the one and only session. bool removedSession = false; - docBroker->startDestroy(id); // We issue a force-save when last editable (non-readonly) session is going away - bool forceSave = docBroker->isLastEditableSession(); + const bool forceSave = docBroker->startDestroy(id); + sessionsCount = docBroker->getSessionsCount(); if (sessionsCount > 1) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits