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

Michael Meeks michael.meeks at collabora.com
Mon Apr 25 09:23:08 UTC 2016


 loolwsd/DocumentBroker.hpp |    2 -
 loolwsd/LOOLWSD.cpp        |    2 -
 loolwsd/TileCache.cpp      |   71 ++++++++++++++++++++-------------------------
 loolwsd/TileCache.hpp      |   20 +++---------
 4 files changed, 39 insertions(+), 56 deletions(-)

New commits:
commit 3e151af9f60b4e0bf4d9707f25bd2b480230a030
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Mon Apr 25 10:21:54 2016 +0100

    Typo fix, and atomic markToDestroy.

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 5a5298f..0abf3f1 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -216,7 +216,7 @@ private:
     std::map<std::string, std::shared_ptr<MasterProcessSession>> _sessions;
     std::unique_ptr<StorageBase> _storage;
     std::unique_ptr<TileCache> _tileCache;
-    bool _markToDestroy;
+    std::atomic<bool> _markToDestroy;
     bool _isModified;
     mutable std::mutex _mutex;
     std::condition_variable _saveCV;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 068f25c..3acc19b 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -510,7 +510,7 @@ private:
                 if (docBroker)
                 {
                     // Still here, but marked to destroy.
-                    Log::error("Timed out while waiting for document to unload befor loading. Service Unavailable.");
+                    Log::error("Timed out while waiting for document to unload before loading. Service Unavailable.");
                     throw WebSocketErrorMessageException(SERVICE_UNAVALABLE_INTERNAL_ERROR);
                 }
             }
commit e64bc9504422b8ae508dcc5875ca270f7d866d9c
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Mon Apr 25 10:04:25 2016 +0100

    Further TileBeingRendered cleanup & re-factor.
    
    Turn TileBeingRendered into an internal implementation detail.

diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index e7c9830..a400981 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -45,30 +45,6 @@ using Poco::URI;
 
 using namespace LOOLProtocol;
 
-TileBeingRendered::TileBeingRendered()
-{
-    _startTime.update();
-}
-
-void TileBeingRendered::subscribe(const std::weak_ptr<MasterProcessSession>& session)
-{
-    std::shared_ptr<MasterProcessSession> cmp = session.lock();
-    for (const auto& s : _subscribers)
-    {
-        if (s.lock().get() == cmp.get())
-        {
-            Log::debug("Redundant request to re-subscribe on a tile");
-            return;
-        }
-    }
-    _subscribers.push_back(session);
-}
-
-std::vector<std::weak_ptr<MasterProcessSession>> TileBeingRendered::getSubscribers()
-{
-    return _subscribers;
-}
-
 TileCache::TileCache(const std::string& docURL,
                      const Timestamp& modifiedTime,
                      const std::string& cacheDir) :
@@ -96,16 +72,17 @@ TileCache::~TileCache()
     Log::info("~TileCache dtor for uri [" + _docURL + "].");
 }
 
-void TileCache::rememberTileAsBeingRendered(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
+struct TileCache::TileBeingRendered
 {
-    const std::string cachedName = cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
-
-    assert(_tilesBeingRendered.find(cachedName) == _tilesBeingRendered.end());
-
-    _tilesBeingRendered[cachedName] = std::make_shared<TileBeingRendered>();
-}
+    Poco::Timestamp _startTime;
+    std::vector<std::weak_ptr<MasterProcessSession>> _subscribers;
+    TileBeingRendered()
+    {
+        _startTime.update();
+    }
+};
 
-std::shared_ptr<TileBeingRendered> TileCache::findTileBeingRendered(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
+std::shared_ptr<TileCache::TileBeingRendered> TileCache::findTileBeingRendered(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
 {
     const std::string cachedName = cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
 
@@ -359,7 +336,7 @@ void TileCache::notifyAndRemoveSubscribers(int part, int width, int height, int
 
     Log::debug("Sending tile message also to subscribers");
 
-    for (auto i: tileBeingRendered->getSubscribers())
+    for (auto i: tileBeingRendered->_subscribers)
     {
         auto subscriber = i.lock();
         if (subscriber)
@@ -391,26 +368,42 @@ void TileCache::notifyAndRemoveSubscribers(int part, int width, int height, int
         }
     }
     forgetTileBeingRendered(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
-
-    lock.unlock();
 }
 
+// FIXME: to be further simplified when we centralize tile messages.
 bool TileCache::isTileBeingRenderedIfSoSubscribe(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, const std::shared_ptr<MasterProcessSession> &subscriber)
 {
     std::unique_lock<std::mutex> lock(_tilesBeingRenderedMutex);
 
     std::shared_ptr<TileBeingRendered> tileBeingRendered = findTileBeingRendered(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
+
     if (tileBeingRendered)
     {
         Log::debug("Tile is already being rendered, subscribing");
         assert(subscriber->getKind() == LOOLSession::Kind::ToClient);
-        tileBeingRendered->subscribe(subscriber);
+
+        for (const auto &s : tileBeingRendered->_subscribers)
+        {
+            if (s.lock().get() == subscriber.get())
+            {
+                Log::debug("Redundant request to re-subscribe on a tile");
+                return true;
+            }
+        }
+        tileBeingRendered->_subscribers.push_back(subscriber);
+
         return true;
     }
-    rememberTileAsBeingRendered(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
-    lock.unlock();
+    else
+    {
+        const std::string cachedName = cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
 
-    return false;
+        assert(_tilesBeingRendered.find(cachedName) == _tilesBeingRendered.end());
+
+        _tilesBeingRendered[cachedName] = std::make_shared<TileBeingRendered>();
+
+        return false;
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index f52533d..7919a47 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -23,18 +23,13 @@
 
 class MasterProcessSession;
 
-class TileBeingRendered
-{
-    Poco::Timestamp _startTime;
-    std::vector<std::weak_ptr<MasterProcessSession>> _subscribers;
-public:
-    TileBeingRendered();
-    void subscribe(const std::weak_ptr<MasterProcessSession>& session);
-    std::vector<std::weak_ptr<MasterProcessSession>> getSubscribers();
-};
-
 class TileCache
 {
+    struct TileBeingRendered;
+
+    std::shared_ptr<TileBeingRendered> findTileBeingRendered(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
+;
+
 public:
     /// When the docURL is a non-file:// url, the timestamp has to be provided by the caller.
     /// For file:// url's, it's ignored.
@@ -44,11 +39,6 @@ public:
 
     TileCache(const TileCache&) = delete;
 
-    void rememberTileAsBeingRendered(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight);
-
-    std::shared_ptr<TileBeingRendered> findTileBeingRendered(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
-;
-
     bool isTileBeingRenderedIfSoSubscribe(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, const std::shared_ptr<MasterProcessSession> &subscriber);
 
     void forgetTileBeingRendered(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight);


More information about the Libreoffice-commits mailing list