[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - vcl/headless

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 8 21:10:52 UTC 2020


 vcl/headless/svpinst.cxx |   24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

New commits:
commit 1eaae412c596585a2ff37fb618341930ea091f05
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Wed Apr 8 14:52:30 2020 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Wed Apr 8 23:10:19 2020 +0200

    headless: re-work microsecond calculation to preserve accuracy.
    
    Should be an almost pure re-factor, that may save a few ms
    in some cases.
    
    Change-Id: Ie9c9e1a3610e1bcc8c12941f230109dd8eb77404
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91925
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx
index 80223ac58904..0247474c60a4 100644
--- a/vcl/headless/svpinst.cxx
+++ b/vcl/headless/svpinst.cxx
@@ -430,23 +430,18 @@ bool SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents)
     {
         if (bWait && ! bEvent)
         {
-            int nTimeoutMS = 0;
+            sal_Int64 nTimeoutMicroS = 0;
             if (m_aTimeout.tv_sec) // Timer is started.
             {
                 timeval Timeout;
                 // determine remaining timeout.
                 gettimeofday (&Timeout, nullptr);
                 if (m_aTimeout > Timeout)
-                {
-                    int nTimeoutMicroS = m_aTimeout.tv_usec - Timeout.tv_usec;
-                    nTimeoutMS = (m_aTimeout.tv_sec - Timeout.tv_sec) * 1000
-                               + nTimeoutMicroS / 1000;
-                    if ( nTimeoutMicroS % 1000 )
-                        nTimeoutMS += 1;
-                }
+                    nTimeoutMicroS = ((m_aTimeout.tv_sec - Timeout.tv_sec) * 1000 * 1000 +
+                                      (m_aTimeout.tv_usec - Timeout.tv_usec));
             }
             else
-                nTimeoutMS = -1; // wait until something happens
+                nTimeoutMicroS = -1; // wait until something happens
 
             ImplSVData* pSVData = ImplGetSVData();
             sal_uInt32 nAcquireCount = ReleaseYieldMutexAll();
@@ -454,25 +449,28 @@ bool SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents)
             if (pSVData->mpPollCallback)
             {
                 // Poll for events from the LOK client.
-                if (nTimeoutMS < 0)
-                    nTimeoutMS = 5000;
+                if (nTimeoutMicroS < 0)
+                    nTimeoutMicroS = 5000 * 1000;
 
                 // External poll.
                 if (pSVData->mpPollClosure != nullptr &&
-                    pSVData->mpPollCallback(pSVData->mpPollClosure, nTimeoutMS * 1000 /* us */) < 0)
+                    pSVData->mpPollCallback(pSVData->mpPollClosure, nTimeoutMicroS) < 0)
                     pSVData->maAppData.mbAppQuit = true;
             }
             else
             {
                 std::unique_lock<std::mutex> g(pMutex->m_WakeUpMainMutex);
                 // wait for doRelease() or Wakeup() to set the condition
-                if (nTimeoutMS == -1)
+                if (nTimeoutMicroS == -1)
                 {
                     pMutex->m_WakeUpMainCond.wait(g,
                             [pMutex]() { return pMutex->m_wakeUpMain; });
                 }
                 else
                 {
+                    int nTimeoutMS = nTimeoutMicroS / 1000;
+                    if ( nTimeoutMicroS % 1000 )
+                        nTimeoutMS += 1;
                     pMutex->m_WakeUpMainCond.wait_for(g,
                             std::chrono::milliseconds(nTimeoutMS),
                             [pMutex]() { return pMutex->m_wakeUpMain; });


More information about the Libreoffice-commits mailing list