[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp

Henry Castro hcastro at collabora.com
Wed Aug 5 15:21:04 PDT 2015


 loolwsd/LOOLSession.cpp |   12 ++++++++----
 loolwsd/LOOLWSD.cpp     |    8 +++++---
 loolwsd/LOOLWSD.hpp     |    2 +-
 3 files changed, 14 insertions(+), 8 deletions(-)

New commits:
commit 0ec12fe11ec22d8a4a7ce1d334b4af2f5465ca98
Author: Henry Castro <hcastro at collabora.com>
Date:   Wed Aug 5 18:19:51 2015 -0400

    loolwsd: fix child fork when debugging one child

diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index c74920f..ac299f4 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -467,13 +467,17 @@ 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);
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ae2ed32..84f6bf5 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -947,10 +947,12 @@ void LOOLWSD::desktopMain()
         else if (pid < 0)
             std::cout << Util::logPrefix() << "Child error: " << strerror(errno);
 
-        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;
+            std::cout << Util::logPrefix() << "Create child session, fork new one" << std::endl;
+            _namedMutexLOOL.unlock();
             if (createComponent() < 0 )
                 break;
         }
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 331e9f3..7b5bfd9 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -39,6 +39,7 @@ public:
     static std::string loSubPath;
     static std::string jail;
     static Poco::SharedMemory _sharedForkChild;
+    static Poco::NamedMutex _namedMutexLOOL;
 
     static const int DEFAULT_CLIENT_PORT_NUMBER = 9980;
     static const int MASTER_PORT_NUMBER = 9981;
@@ -69,7 +70,6 @@ private:
     static int _numPreSpawnedChildren;
     static std::mutex _rngMutex;
     static Poco::Random _rng;
-    static Poco::NamedMutex _namedMutexLOOL;
 
 #if ENABLE_DEBUG
 public:


More information about the Libreoffice-commits mailing list