[Libreoffice-commits] online.git: net/Socket.hpp

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 10 10:24:38 UTC 2019


 net/Socket.hpp |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

New commits:
commit 579c827363ce35cb7912de34a77d89b8d83b0065
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Jun 10 11:17:02 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Mon Jun 10 12:24:17 2019 +0200

    unipoll: allow LOK's Yield callback to be called from any thread.
    
    Change-Id: I1ab46135919a1f06f814cc8702991592c84d28a7
    Reviewed-on: https://gerrit.libreoffice.org/73752
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 2d96d1981..5ebdc5560 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -473,12 +473,30 @@ public:
         assert(_stop || sameThread);
     }
 
+    /// Kit poll can be called from LOK's Yield in any thread, adapt to that.
+    void checkAndReThread()
+    {
+        if (InhibitThreadChecks)
+            return;
+        std::thread::id us = std::thread::id();
+        if (_owner == us)
+            return; // all well
+        LOG_DBG("Ununusual - SocketPoll used from a new thread");
+        _owner = us;
+        for (auto it : _pollSockets)
+            it->setThreadOwner(us);
+        // _newSockets are adapted as they are inserted.
+    }
+
     /// Poll the sockets for available data to read or buffer to write.
     /// Returns the return-value of poll(2): 0 on timeout,
     /// -1 for error, and otherwise the number of events signalled.
     int poll(int timeoutMaxMs)
     {
-        assertCorrectThread();
+        if (_runOnClientThread)
+            checkAndReThread();
+        else
+            assertCorrectThread();
 
         std::chrono::steady_clock::time_point now =
             std::chrono::steady_clock::now();


More information about the Libreoffice-commits mailing list