[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue Apr 5 02:58:35 UTC 2016


 loolwsd/LOOLBroker.cpp |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

New commits:
commit 94c30334081265ca1dd308784998b07cf5843e61
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon Apr 4 20:46:11 2016 -0400

    loolwsd: wait for the Connection thread to exit before destroying
    
    Also, the thread is joinable only once.
    
    Change-Id: Ia0d8e4c350a6bedcf15873c751fffa837460e4bf
    Reviewed-on: https://gerrit.libreoffice.org/23821
    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 072e8ff..14b6299 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -28,7 +28,6 @@
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
 #include <Poco/Exception.h>
-#include <Poco/Mutex.h>
 #include <Poco/Net/HTTPClientSession.h>
 #include <Poco/Net/HTTPRequest.h>
 #include <Poco/Net/HTTPResponse.h>
@@ -242,6 +241,7 @@ public:
     {
         Log::info("~Connection dtor in child for " + _session->getId());
         stop();
+        join();
     }
 
     std::shared_ptr<WebSocket> getWebSocket() const { return _ws; }
@@ -264,7 +264,13 @@ public:
 
     void join()
     {
-        _thread.join();
+        // The thread is joinable only once.
+        std::unique_lock<std::mutex> lock(_threadMutex);
+        if (!_joined)
+        {
+            _thread.join();
+            _joined = true;
+        }
     }
 
     void handle(std::shared_ptr<TileQueue> queue, const std::string& firstLine, char* buffer, int n)
@@ -369,7 +375,9 @@ private:
     Thread _thread;
     std::shared_ptr<ChildProcessSession> _session;
     std::shared_ptr<WebSocket> _ws;
-    volatile bool _stop;
+    std::atomic<unsigned> _stop;
+    std::mutex _threadMutex;
+    std::atomic<unsigned> _joined;
 };
 
 /// A document container.


More information about the Libreoffice-commits mailing list