loolwsd/LOOLWSD.cpp |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit 4bc26f25d51c336bf904c0b7e07a26bc486959a4
Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
Date:   Mon Apr 4 22:40:18 2016 -0400

    loolwsd: wait for new child instances if none is available
    
    Change-Id: If7de4ae73e9432694a0cf032b19d7e0ab9c5a9d1
    Reviewed-on: https://gerrit.libreoffice.org/23824
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9c29d63..6b05fca 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -172,8 +172,10 @@ using Poco::XML::Node;
 using Poco::XML::NodeList;
 
 /// New LOK child processes ready to host documents.
+//TODO: Move to a more sensible namespace.
 static std::vector<std::shared_ptr<ChildProcess>> newChilds;
 static std::mutex newChildsMutex;
+static std::condition_variable newChildsCV;
 static std::map<std::string, std::shared_ptr<DocumentBroker>> docBrokers;
 static std::mutex docBrokersMutex;
 
@@ -199,7 +201,8 @@ std::shared_ptr<ChildProcess> getNewChild()
         IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
     }
 
-    if (available > 0)
+    const auto timeout = std::chrono::milliseconds(CHILD_TIMEOUT_SECS * 1000);
+    if (newChildsCV.wait_for(lock, timeout, [](){ return !newChilds.empty(); 
}))
     {
         auto child = newChilds.back();
         newChilds.pop_back();
@@ -671,6 +674,7 @@ public:
             std::unique_lock<std::mutex> lock(newChildsMutex);
             newChilds.emplace_back(std::make_shared<ChildProcess>(pid, ws));
             Log::info("Have " + std::to_string(newChilds.size()) + " childs.");
+            newChildsCV.notify_one();
             return;
         }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to