[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Oct 31 06:11:16 UTC 2016


 loolwsd/LOOLWSD.cpp |   67 +++++++++++++++++++++++++---------------------------
 1 file changed, 33 insertions(+), 34 deletions(-)

New commits:
commit 4ba5bedf6adfdc92a4ef2624ef2d6c255fd17d37
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon Oct 31 01:28:40 2016 -0400

    loolwsd: explicitly scope DocumentBroker mutex
    
    Change-Id: I64629774ec745f47e7376231a3ca569bcbfffaac
    Reviewed-on: https://gerrit.libreoffice.org/30424
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 59f8322..3956e29 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -713,49 +713,48 @@ private:
         const auto docKey = DocumentBroker::getDocKey(uriPublic);
         std::shared_ptr<DocumentBroker> docBroker;
 
-        // scope the DocBrokersLock
-        {
-            std::unique_lock<std::mutex> DocBrokersLock(DocBrokersMutex);
+        std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex);
 
-            if (TerminationFlag)
-            {
-                Log::error("Termination flag set. No loading new session [" + id + "]");
-                return;
-            }
+        if (TerminationFlag)
+        {
+            Log::error("Termination flag set. No loading new session [" + id + "]");
+            return;
+        }
 
-            cleanupDocBrokers();
+        cleanupDocBrokers();
 
-            // Lookup this document.
-            auto it = DocBrokers.find(docKey);
-            if (it != DocBrokers.end())
+        // Lookup this document.
+        auto it = DocBrokers.find(docKey);
+        if (it != DocBrokers.end())
+        {
+            // Get the DocumentBroker from the Cache.
+            Log::debug("Found DocumentBroker for docKey [" + docKey + "].");
+            docBroker = it->second;
+            assert(docBroker);
+        }
+        else
+        {
+            // New Document.
+#if MAX_DOCUMENTS > 0
+            if (DocBrokers.size() + 1 > MAX_DOCUMENTS)
             {
-                // Get the DocumentBroker from the Cache.
-                Log::debug("Found DocumentBroker for docKey [" + docKey + "].");
-                docBroker = it->second;
-                assert(docBroker);
+                Log::error() << "Limit on maximum number of open documents of "
+                             << MAX_DOCUMENTS << " reached." << Log::end;
+                shutdownLimitReached(*ws);
+                return;
             }
-            else
-            {
-                // New Document.
-#if MAX_DOCUMENTS > 0
-                if (DocBrokers.size() + 1 > MAX_DOCUMENTS)
-                {
-                    Log::error() << "Limit on maximum number of open documents of "
-                                 << MAX_DOCUMENTS << " reached." << Log::end;
-                    shutdownLimitReached(*ws);
-                    return;
-                }
 #endif
 
-                // Store a dummy (marked to destroy) document broker until we
-                // have the real one, so that the other requests block
-                Log::debug("Inserting a dummy DocumentBroker for docKey [" + docKey + "] temporarily.");
+            // Store a dummy (marked to destroy) document broker until we
+            // have the real one, so that the other requests block
+            Log::debug("Inserting a dummy DocumentBroker for docKey [" + docKey + "] temporarily.");
 
-                std::shared_ptr<DocumentBroker> tempBroker = std::make_shared<DocumentBroker>();
-                DocBrokers.emplace(docKey, tempBroker);
-            }
+            std::shared_ptr<DocumentBroker> tempBroker = std::make_shared<DocumentBroker>();
+            DocBrokers.emplace(docKey, tempBroker);
         }
 
+        docBrokersLock.unlock();
+
         if (docBroker && docBroker->isMarkedToDestroy())
         {
             // If this document is going out, wait.
@@ -767,7 +766,7 @@ private:
                 std::this_thread::sleep_for(std::chrono::milliseconds(POLL_TIMEOUT_MS));
 
                 std::unique_lock<std::mutex> lock(DocBrokersMutex);
-                auto it = DocBrokers.find(docKey);
+                it = DocBrokers.find(docKey);
                 if (it == DocBrokers.end())
                 {
                     // went away successfully


More information about the Libreoffice-commits mailing list