[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Thu Jan 21 08:07:20 PST 2016
loolwsd/LOOLBroker.cpp | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
New commits:
commit a882ed1aa14273d5c59f8e0dc0a551b6824648a4
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Thu Jan 21 09:57:10 2016 -0500
loolwsd: thread safety fixes in broker
Change-Id: Ibfff184ad294c14d6583f7a8282edc4e2742ad52
Reviewed-on: https://gerrit.libreoffice.org/21685
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 65e2a16..62ae29e 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -72,7 +72,7 @@ static std::chrono::steady_clock::time_point lastMaintenanceTime = std::chrono::
static unsigned int childCounter = 0;
static signed numPreSpawnedChildren = 0;
-static std::mutex forkMutex;
+static std::recursive_mutex forkMutex;
static std::map<Process::PID, int> _childProcesses;
static std::map<std::string, Process::PID> _cacheURL;
@@ -82,7 +82,7 @@ namespace
/// of a child. Returns -1 on error.
int getChildPipe(const Process::PID pid)
{
- std::lock_guard<std::mutex> lock(forkMutex);
+ std::lock_guard<std::recursive_mutex> lock(forkMutex);
const auto it = _childProcesses.find(pid);
return (it != _childProcesses.end() ? it->second : -1);
}
@@ -91,7 +91,7 @@ namespace
/// invalidates the URL cache.
void removeChild(const Process::PID pid)
{
- std::lock_guard<std::mutex> lock(forkMutex);
+ std::lock_guard<std::recursive_mutex> lock(forkMutex);
const auto it = _childProcesses.find(pid);
if (it != _childProcesses.end())
{
@@ -277,6 +277,8 @@ public:
void verifyChilds()
{
+ std::lock_guard<std::recursive_mutex> lock(forkMutex);
+
Log::trace("Verifying Childs.");
std::string aMessage;
bool bError = false;
@@ -307,8 +309,9 @@ public:
Process::PID searchURL(const std::string& aURL)
{
- const std::string aMessage = "search " + aURL + "\r\n";
+ std::lock_guard<std::recursive_mutex> lock(forkMutex);
+ const std::string aMessage = "search " + aURL + "\r\n";
Process::PID nPID = -1;
for (auto& it : _childProcesses)
{
@@ -356,6 +359,8 @@ public:
void handleInput(const std::string& aMessage)
{
+ std::lock_guard<std::recursive_mutex> lock(forkMutex);
+
StringTokenizer tokens(aMessage, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
if (tokens[0] == "request" && tokens.count() == 3)
{
@@ -842,7 +847,7 @@ int main(int argc, char** argv)
{
if (forkCounter > 0)
{
- std::lock_guard<std::mutex> lock(forkMutex);
+ std::lock_guard<std::recursive_mutex> lock(forkMutex);
// Figure out how many children we need.
const signed total = _childProcesses.size();
More information about the Libreoffice-commits
mailing list