[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Wed Mar 23 00:01:58 UTC 2016
loolwsd/LOOLKit.cpp | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
New commits:
commit 18829fda3b0b45118b99c193a72cd48469b4eb3f
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sat Mar 19 17:52:05 2016 -0400
loolwsd: opportunistic kit session cleanup
When the Document lock cannot be taken
purging doesn't block (which would block
the kit-broker pipe). Instead, purging
is done only when the lock is taken,
otherwise we try again later.
Change-Id: Id201f1c67803d9b1e765e8c55f85206795fe53c0
Reviewed-on: https://gerrit.libreoffice.org/23448
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index dcf5e61..6158642 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -403,7 +403,7 @@ public:
<< " on jailId: " << _jailId << Log::end;
// Open websocket connection between the child process and the
- // parent. The parent forwards us requests that it can't handle.
+ // parent. The parent forwards us requests that it can't handle (i.e most).
HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER);
cs.setTimeout(0);
@@ -430,11 +430,18 @@ public:
/// Purges dead connections and returns
/// the remaining number of clients.
+ /// Returns -1 on failure.
size_t purgeSessions()
{
std::vector<std::shared_ptr<ChildProcessSession>> deadSessions;
+ size_t num_connections = 0;
{
- std::unique_lock<std::recursive_mutex> lock(_mutex);
+ std::unique_lock<std::recursive_mutex> lock(_mutex, std::defer_lock);
+ if (!lock.try_lock())
+ {
+ // Not a good time, try later.
+ return -1;
+ }
for (auto it =_connections.cbegin(); it != _connections.cend(); )
{
@@ -448,6 +455,8 @@ public:
++it;
}
}
+
+ num_connections = _connections.size();
}
// Don't destroy sessions while holding our lock.
@@ -456,15 +465,15 @@ public:
// and the dtor tries to take its lock (which is taken).
deadSessions.clear();
- std::unique_lock<std::recursive_mutex> lock(_mutex);
- return _connections.size();
+ return num_connections;
}
/// Returns true if at least one *live* connection exists.
/// Does not consider user activity, just socket status.
bool hasConnections()
{
- return purgeSessions() > 0;
+ // -ve values for failure.
+ return purgeSessions() != 0;
}
/// Returns true if there is no activity and
More information about the Libreoffice-commits
mailing list