[Libreoffice-commits] online.git: common/MessageQueue.hpp wsd/ClientSession.cpp wsd/ClientSession.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Jan 23 04:40:03 UTC 2017
common/MessageQueue.hpp | 13 +++++++++----
wsd/ClientSession.cpp | 3 ---
wsd/ClientSession.hpp | 5 +++++
3 files changed, 14 insertions(+), 7 deletions(-)
New commits:
commit f3a85a7bf04bf8c0b215304a140dcffde645aefa
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Thu Jan 19 23:24:23 2017 -0500
wsd: MessageQueueBase support no empty items
Throw when empty payload is enqueued
and return empty payload on get timeout
(instead of throwing).
Change-Id: Iab5df775caa46d5c212d0850645cda6cca16f20b
Reviewed-on: https://gerrit.libreoffice.org/33421
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/common/MessageQueue.hpp b/common/MessageQueue.hpp
index 0ae4658..34cbe8a 100644
--- a/common/MessageQueue.hpp
+++ b/common/MessageQueue.hpp
@@ -39,6 +39,11 @@ public:
/// Thread safe insert the message.
void put(const Payload& value)
{
+ if (value.empty())
+ {
+ throw std::runtime_error("Cannot queue empty item.");
+ }
+
std::unique_lock<std::mutex> lock(_mutex);
put_impl(value);
lock.unlock();
@@ -52,6 +57,7 @@ public:
/// Thread safe obtaining of the message.
/// timeoutMs can be 0 to signify infinity.
+ /// Returns an empty payload on timeout.
Payload get(const unsigned timeoutMs = 0)
{
std::unique_lock<std::mutex> lock(_mutex);
@@ -59,9 +65,9 @@ public:
if (timeoutMs > 0)
{
if (!_cv.wait_for(lock, std::chrono::milliseconds(timeoutMs),
- [this] { return wait_impl(); }))
+ [this] { return wait_impl(); }))
{
- throw std::runtime_error("Timed out waiting to get queue item.");
+ return Payload();
}
}
else
@@ -72,7 +78,6 @@ public:
return get_impl();
}
-
/// Thread safe removal of all the pending messages.
void clear()
{
@@ -118,7 +123,7 @@ protected:
std::vector<Payload> _queue;
private:
- std::mutex _mutex;
+ mutable std::mutex _mutex;
std::condition_variable _cv;
};
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 4ed0b29..e32d53b 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -50,9 +50,6 @@ ClientSession::~ClientSession()
{
LOG_INF("~ClientSession dtor [" << getName() << "].");
- // Release the save-as queue.
- _saveAsQueue.put("");
-
stop();
if (_senderThread.joinable())
{
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index ed78a44..57345bb 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -83,6 +83,11 @@ public:
std::string getSaveAsUrl(const unsigned timeoutMs)
{
const auto payload = _saveAsQueue.get(timeoutMs);
+ if (payload.empty())
+ {
+ throw std::runtime_error("Timed-out while getting save-as URL.");
+ }
+
return std::string(payload.data(), payload.size());
}
More information about the Libreoffice-commits
mailing list