[Libreoffice-commits] online.git: Branch 'private/hcvcastro/forking' - loolwsd/LOOLBroker.cpp loolwsd/LOOLWSD.hpp loolwsd/MasterProcessSession.cpp

Henry Castro hcastro at collabora.com
Tue Aug 4 18:50:55 PDT 2015


 loolwsd/LOOLBroker.cpp           |   10 +++++++---
 loolwsd/LOOLWSD.hpp              |    2 +-
 loolwsd/MasterProcessSession.cpp |   11 ++++++++---
 3 files changed, 16 insertions(+), 7 deletions(-)

New commits:
commit 5ade3f91670464ca5828c39c38067c25408f63da
Author: Henry Castro <hcastro at collabora.com>
Date:   Tue Aug 4 21:49:33 2015 -0400

    loolwsd: fix child fork when debugging one child.

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 13c380d..478931b 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -21,6 +21,7 @@
 #include <Poco/Process.h>
 #include <Poco/Thread.h>
 #include <Poco/SharedMemory.h>
+#include <Poco/NamedMutex.h>
 
 #include "Util.hpp"
 
@@ -239,6 +240,7 @@ static void startupLibreOfficeKit(int nLOKits, std::string loSubPath, Poco::UInt
 }
 
 static int timeoutCounter = 0;
+Poco::NamedMutex _namedMutexLOOL("loolwsd");
 
 // Broker process
 int main(int argc, char** argv)
@@ -435,10 +437,12 @@ int main(int argc, char** argv)
         else if (pid < 0)
             std::cout << Util::logPrefix() << "Child error: " << strerror(errno) << std::endl;
 
-        if ( _sharedForkChild.begin()[0] )
+        if ( _sharedForkChild.begin()[0] > 0 )
         {
-            _sharedForkChild.begin()[0] = 0;
-            std::cout << Util::logPrefix() << "No availabe child session, fork new one" << std::endl;
+            _namedMutexLOOL.lock();
+            _sharedForkChild.begin()[0] = _sharedForkChild.begin()[0] - 1;
+            _namedMutexLOOL.unlock();
+            std::cout << Util::logPrefix() << "Create child session, fork new one" << std::endl;
             if (createLibreOfficeKit(loSubPath, _childId) < 0 )
                 break;
         }
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 2617cff..1ad7187 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -46,6 +46,7 @@ public:
     static const int MAINTENANCE_INTERVAL = 1;
     static const std::string CHILD_URI;
     static const std::string PIDLOG;
+    static Poco::NamedMutex _namedMutexLOOL;
 
 protected:
     void initialize(Poco::Util::Application& self) override;
@@ -64,7 +65,6 @@ private:
     static int _numPreSpawnedChildren;
     static std::mutex _rngMutex;
     static Poco::Random _rng;
-    static Poco::NamedMutex _namedMutexLOOL;
 
 #if ENABLE_DEBUG
 public:
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index c0e98d4..8d18cd9 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -396,11 +396,16 @@ void MasterProcessSession::dispatchChild()
     childSession = *(_availableChildSessions.begin());
 
     _availableChildSessions.erase(childSession);
-    std::cout << Util::logPrefix() << "_availableChildSessions size=" << _availableChildSessions.size() << std::endl;
-    if (_availableChildSessions.size() == 0)
-        LOOLWSD::_sharedForkChild.begin()[0] = 1;
     lock.unlock();
 
+    if (_availableChildSessions.size() == 0)
+    {
+        LOOLWSD::_namedMutexLOOL.lock();
+        std::cout << Util::logPrefix() << "No available child sessions, queue new child session" << std::endl;
+        LOOLWSD::_sharedForkChild.begin()[0] = (LOOLWSD::_sharedForkChild.begin()[0] > 0 ? LOOLWSD::_sharedForkChild.begin()[0] + 1 : 1);
+        LOOLWSD::_namedMutexLOOL.unlock();
+    }
+
     // Assume a valid URI
     URI aUri(_docURL);
 


More information about the Libreoffice-commits mailing list