sd/source/ui/remotecontrol/Transmitter.cxx |   49 ++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 18 deletions(-)

New commits:
commit 58594eaa9f4df52f919cf5b9c43959bcb9c2c452
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Nov 24 12:20:33 2023 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Nov 27 10:15:33 2023 +0100

    sd: remote: release Transmitter mutex when sending
    
    The Bluetooth communication appears to be astonishingly slow on my
    system; the socket is deliberately cleared of O_NONBLOCK and what's even
    worse is that the Mutex that is held while sending prevents the main
    thread from adding new messages to the queues.
    
    It looks like there should be no issue with releasing the Mutex while
    sending, and if a separate Transmitter thread is used in the first place
    it makes no sense to hold the Mutex while doing so.
    
    Change-Id: Ic993e6c7a7799832c86fd4dd8c6ddad9dab1780b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159924
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sd/source/ui/remotecontrol/Transmitter.cxx 
b/sd/source/ui/remotecontrol/Transmitter.cxx
index cca6a3bee460..7992e5b94bd6 100644
--- a/sd/source/ui/remotecontrol/Transmitter.cxx
+++ b/sd/source/ui/remotecontrol/Transmitter.cxx
@@ -27,29 +27,42 @@ void SAL_CALL Transmitter::run()
     {
         mProcessingRequired.wait();
 
-        ::osl::MutexGuard aGuard( mMutex );
+        OString aMessage;
+        bool isHighPrio = {};
 
-        if ( mFinishRequested ) {
-            return;
-        }
-        if ( !mHighPriority.empty() )
-        {
-            OString aMessage( mHighPriority.front() );
-            mHighPriority.pop();
-            SAL_INFO( "sdremote.bluetooth", "write high prio line '" << 
aMessage << "'" );
-            pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
-        }
-        else if ( !mLowPriority.empty() )
         {
-            OString aMessage( mLowPriority.front() );
-            mLowPriority.pop();
-            SAL_INFO( "sdremote.bluetooth", "write normal line '" << aMessage 
<< "'" );
-            pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
+            ::osl::MutexGuard aGuard(mMutex);
+
+            if (mFinishRequested) {
+                return;
+            }
+            if (!mHighPriority.empty())
+            {
+                aMessage = mHighPriority.front();
+                mHighPriority.pop();
+                isHighPrio = true;
+            }
+            else if (!mLowPriority.empty())
+            {
+                aMessage = mLowPriority.front();
+                mLowPriority.pop();
+                isHighPrio = false;
+            }
         }
 
-        if ( mLowPriority.empty() && mHighPriority.empty())
+        SAL_INFO("sdremote.bluetooth", "write " << (isHighPrio ? "high prio" : 
"normal") << " line '" << aMessage << "'");
+        // pStreamSocket is owned by Communicator, which joins this thread
+        // before destroying pStreamSocket so it can't die here.
+        // Sending is SLOW and blocks!
+        pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
+
         {
-            mProcessingRequired.reset();
+            ::osl::MutexGuard aGuard(mMutex);
+
+            if (mLowPriority.empty() && mHighPriority.empty())
+            {
+                mProcessingRequired.reset();
+            }
         }
     }
 }

Reply via email to