wsd/DocumentBroker.cpp | 34 ++++++++++------------------------ wsd/DocumentBroker.hpp | 10 +--------- wsd/LOOLWSD.cpp | 4 ++-- 3 files changed, 13 insertions(+), 35 deletions(-)
New commits: commit cbd00bf7c8600afb0f7ec09a8ad90f1b5ed2f298 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Mar 12 13:56:42 2017 -0400 wsd: simplify DocumentBroker construction DocumentBrokerPoll is always owned by a single DocumentBroker instance, so we can hold a reference to it. This eliminates the need to hold a shared_ptr to the owner which, in turn, eliminates the need for a create wrapper. Change-Id: I954c9dddcc3b2cfdd5dfcc8248ab3d47a897f684 Reviewed-on: https://gerrit.libreoffice.org/35113 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index c4c3307..1b47d68 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -114,23 +114,22 @@ std::string DocumentBroker::getDocKey(const Poco::URI& uri) } /// The Document Broker Poll - one of these in a thread per document -class DocumentBroker::DocumentBrokerPoll : public TerminatingPoll +class DocumentBroker::DocumentBrokerPoll final : public TerminatingPoll { - std::shared_ptr<DocumentBroker> _docBroker; + /// The DocumentBroker owning us. + DocumentBroker& _docBroker; + public: - DocumentBrokerPoll(const std::string &threadName) - : TerminatingPoll(threadName) - { - } - void setDocumentBroker(const std::shared_ptr<DocumentBroker> &docBroker) + DocumentBrokerPoll(const std::string &threadName, DocumentBroker& docBroker) : + TerminatingPoll(threadName), + _docBroker(docBroker) { - _docBroker = docBroker; } virtual void pollingThread() { - assert (_docBroker); - _docBroker->pollThread(); + // Delegate to the docBroker. + _docBroker.pollThread(); } }; @@ -152,7 +151,7 @@ DocumentBroker::DocumentBroker(const std::string& uri, _cursorPosY(0), _cursorWidth(0), _cursorHeight(0), - _poll(new DocumentBrokerPoll("docbrk_poll")), + _poll(new DocumentBrokerPoll("docbrk_poll", *this)), _tileVersion(0), _debugRenderedTileCount(0) { @@ -164,19 +163,6 @@ DocumentBroker::DocumentBroker(const std::string& uri, _stop = false; } -std::shared_ptr<DocumentBroker> DocumentBroker::create( - const std::string& uri, - const Poco::URI& uriPublic, - const std::string& docKey, - const std::string& childRoot) -{ - std::shared_ptr<DocumentBroker> docBroker = std::make_shared<DocumentBroker>(uri, uriPublic, docKey, childRoot); - - docBroker->_poll->setDocumentBroker(docBroker); - - return docBroker; -} - void DocumentBroker::startThread() { _poll->startThread(); diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 0ca4ab7..2d30802 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -212,19 +212,11 @@ public: /// Dummy document broker that is marked to destroy. DocumentBroker(); - /// Use create - not this constructor ... - /// FIXME: friend with make_shared etc. + /// Construct DocumentBroker with URI, docKey, and root path. DocumentBroker(const std::string& uri, const Poco::URI& uriPublic, const std::string& docKey, const std::string& childRoot); -public: - static std::shared_ptr<DocumentBroker> create( - const std::string& uri, - const Poco::URI& uriPublic, - const std::string& docKey, - const std::string& childRoot); - ~DocumentBroker(); diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index eb06f5f..a459bf4 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -1296,7 +1296,7 @@ static std::shared_ptr<DocumentBroker> createDocBroker(WebSocketHandler& ws, // Set the one we just created. LOG_DBG("New DocumentBroker for docKey [" << docKey << "]."); - auto docBroker = DocumentBroker::create(uri, uriPublic, docKey, LOOLWSD::ChildRoot); + auto docBroker = std::make_shared<DocumentBroker>(uri, uriPublic, docKey, LOOLWSD::ChildRoot); DocBrokers.emplace(docKey, docBroker); LOG_TRC("Have " << DocBrokers.size() << " DocBrokers after inserting [" << docKey << "]."); @@ -1958,7 +1958,7 @@ private: std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex); LOG_DBG("New DocumentBroker for docKey [" << docKey << "]."); - auto docBroker = DocumentBroker::create(fromPath, uriPublic, docKey, LOOLWSD::ChildRoot); + auto docBroker = std::make_shared<DocumentBroker>(fromPath, uriPublic, docKey, LOOLWSD::ChildRoot); cleanupDocBrokers(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits