[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/LOOLWSD.cpp loolwsd/TileCache.cpp loolwsd/Util.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue May 3 00:00:38 UTC 2016


 loolwsd/DocumentBroker.cpp |    2 +-
 loolwsd/LOOLWSD.cpp        |    2 +-
 loolwsd/TileCache.cpp      |    4 ++--
 loolwsd/Util.hpp           |    7 +++++++
 4 files changed, 11 insertions(+), 4 deletions(-)

New commits:
commit 6c57e9be4d9992ef1ab32b667e808c6143936ebf
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon May 2 19:17:46 2016 -0400

    loolwsd: helper to assert a lock is already taken
    
    Change-Id: Id28f7a39a4d45ea6ad391015364467dc8ded3e66
    Reviewed-on: https://gerrit.libreoffice.org/24599
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 8f50e32..0d88d75 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -253,7 +253,7 @@ bool DocumentBroker::autoSave(const bool force, const size_t waitTimeoutMs)
 bool DocumentBroker::sendUnoSave()
 {
     Log::info("Autosave triggered for doc [" + _docKey + "].");
-    assert(!_mutex.try_lock());
+    Util::assertIsLocked(_mutex);
 
     // Save using session holding the edit-lock
     for (auto& sessionIt: _sessions)
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5de9afc..6f9aee5 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -167,7 +167,7 @@ static int careerSpanSeconds = 0;
 
 static void forkChildren(const int number)
 {
-    assert(!newChildrenMutex.try_lock()); // check it is held.
+    Util::assertIsLocked(newChildrenMutex);
 
     if (number > 0)
     {
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 6d42158..856c684 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -89,7 +89,7 @@ std::shared_ptr<TileCache::TileBeingRendered> TileCache::findTileBeingRendered(i
 {
     const std::string cachedName = cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
 
-    assert(!_tilesBeingRenderedMutex.try_lock());
+    Util::assertIsLocked(_tilesBeingRenderedMutex);
 
     const auto tile = _tilesBeingRendered.find(cachedName);
     return (tile != _tilesBeingRendered.end() ? tile->second : nullptr);
@@ -99,7 +99,7 @@ void TileCache::forgetTileBeingRendered(int part, int width, int height, int til
 {
     const std::string cachedName = cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
 
-    assert(!_tilesBeingRenderedMutex.try_lock());
+    Util::assertIsLocked(_tilesBeingRenderedMutex);
 
     assert(_tilesBeingRendered.find(cachedName) != _tilesBeingRendered.end());
     _tilesBeingRendered.erase(cachedName);
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 00cf54c..28cdb94 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -56,6 +56,13 @@ namespace Util
                               int bufferWidth, int bufferHeight,
                               std::vector<char>& output, LibreOfficeKitTileMode mode);
 
+    /// Assert that a lock is already taken.
+    template <typename T>
+    void assertIsLocked(T& lock)
+    {
+        assert(!lock.try_lock());
+    }
+
     /// Safely remove a file or directory.
     /// Supresses exception when the file is already removed.
     /// This can happen when there is a race (unavoidable) or when


More information about the Libreoffice-commits mailing list