[Libreoffice-commits] online.git: wsd/TileCache.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Dec 12 00:29:10 UTC 2016
wsd/TileCache.cpp | 57 ++++++++++++++++++++++++++++++++++--------------------
1 file changed, 36 insertions(+), 21 deletions(-)
New commits:
commit d3c2a320aec3669996d17d997065d7546c15320c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Thu Dec 8 23:08:50 2016 -0500
loolwsd: refactor tile sending to offload on thread
Change-Id: I6537ca407dc64a0a78a33ba823a43e5ead570848
Reviewed-on: https://gerrit.libreoffice.org/31881
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index 8608cfa..8eb2c0e 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -145,6 +145,11 @@ std::unique_ptr<std::fstream> TileCache::lookupTile(const TileDesc& tile)
return nullptr;
}
+static void enqueueTask(const std::function<void()>& func)
+{
+ func();
+}
+
void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, const size_t size)
{
std::unique_lock<std::mutex> lock(_tilesBeingRenderedMutex);
@@ -175,23 +180,28 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, const
auto& output = *payload;
output.resize(response.size() + 1 + size);
+ // Send to first subscriber as-is (without cache marker).
std::memcpy(output.data(), response.data(), response.size());
output[response.size()] = '\n';
std::memcpy(output.data() + response.size() + 1, data, size);
- // Send to first subscriber as-is (without cache marker).
- auto firstSubscriber = tileBeingRendered->_subscribers[0].lock();
- if (firstSubscriber)
- {
- try
- {
- firstSubscriber->sendBinaryFrame(output.data(), output.size());
- }
- catch (const std::exception& ex)
+ auto& firstSubscriber = tileBeingRendered->_subscribers[0];
+ enqueueTask([firstSubscriber, payload]()
{
- Log::warn("Failed to send tile to " + firstSubscriber->getName() + ": " + ex.what());
+ auto session = firstSubscriber.lock();
+ if (session)
+ {
+ try
+ {
+ session->sendBinaryFrame(payload->data(), payload->size());
+ }
+ catch (const std::exception& ex)
+ {
+ LOG_ERR("Failed to send tile to " << session->getName() << ": " << ex.what());
+ }
+ }
}
- }
+ );
// All others must get served from the cache.
response += " renderid=cached\n";
@@ -201,18 +211,23 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, const
for (size_t i = 1; i < tileBeingRendered->_subscribers.size(); ++i)
{
- auto subscriber = tileBeingRendered->_subscribers[i].lock();
- if (subscriber)
- {
- try
+ auto& subscriber = tileBeingRendered->_subscribers[i];
+ enqueueTask([subscriber, payload]()
{
- subscriber->sendBinaryFrame(output.data(), output.size());
+ auto session = subscriber.lock();
+ if (session)
+ {
+ try
+ {
+ session->sendBinaryFrame(payload->data(), payload->size());
+ }
+ catch (const std::exception& ex)
+ {
+ LOG_ERR("Failed to send tile to " << session->getName() << ": " << ex.what());
+ }
+ }
}
- catch (const std::exception& ex)
- {
- Log::warn("Failed to send tile to " + subscriber->getName() + ": " + ex.what());
- }
- }
+ );
}
}
else
More information about the Libreoffice-commits
mailing list