summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2020-04-08 14:52:30 +0100
committerMichael Meeks <michael.meeks@collabora.com>2020-04-08 23:10:19 +0200
commit1eaae412c596585a2ff37fb618341930ea091f05 (patch)
tree9b73b7aa700f2966bd4b16823596938fb007eeef
parent741127f2cc995bb8dc8b4ee57145fa5387af227e (diff)
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@gmail.com> Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r--vcl/headless/svpinst.cxx24
1 files changed, 11 insertions, 13 deletions
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; });