vcl/headless/svpinst.cxx | 45 +++++++++++++++++++------------------------ vcl/inc/headless/svpinst.hxx | 4 --- 2 files changed, 21 insertions(+), 28 deletions(-)
New commits: commit 282755759e1a7eee5fe91489b28fd84738179bbc Author: Tor Lillqvist <[email protected]> AuthorDate: Tue Feb 25 18:36:57 2025 +0200 Commit: Caolán McNamara <[email protected]> CommitDate: Tue Dec 2 09:25:01 2025 +0100 Drop use of <sys/time.h> in vcl/headless/svpinst.cxx Instead use <tools/time.hxx> functionality, more specifically tools::Time::GetMonotonicTicks(). More portable. Change-Id: If05de20ad637e22fd2ab6c8287796a8e31c6d90d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194568 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx index 4220f5224ff6..a7c2eeeb266d 100644 --- a/vcl/headless/svpinst.cxx +++ b/vcl/headless/svpinst.cxx @@ -21,8 +21,9 @@ #include <mutex> +#if !defined(ANDROID) && !defined(IOS) && !defined(EMSCRIPTEN) #include <pthread.h> -#include <sys/time.h> +#endif #include <sal/types.h> @@ -46,10 +47,9 @@ #include <salframe.hxx> #include <svdata.hxx> -// FIXME: remove when we re-work the svp mainloop -#include <unx/salunxtime.h> #include <tools/debug.hxx> #include <comphelper/lok.hxx> +#include <tools/time.hxx> #include <o3tl/unreachable.hxx> #if defined EMSCRIPTEN @@ -91,9 +91,8 @@ static void atfork_child() SvpSalInstance::SvpSalInstance( std::unique_ptr<SalYieldMutex> pMutex ) : SalGenericInstance( std::move(pMutex) ) { - m_aTimeout.tv_sec = 0; - m_aTimeout.tv_usec = 0; - m_nTimeoutMS = 0; + m_nTimeout = 0; + m_nTimeoutMS = 0; m_MainThread = osl::Thread::getCurrentIdentifier(); if( s_pDefaultInstance == nullptr ) @@ -153,18 +152,17 @@ void SvpSalInstance::Wakeup(SvpRequest const request) bool SvpSalInstance::CheckTimeout( bool bExecuteTimers ) { bool bRet = false; - if( m_aTimeout.tv_sec ) // timer is started + if( m_nTimeout ) // timer is started { - timeval aTimeOfDay; - gettimeofday( &aTimeOfDay, nullptr ); - if( aTimeOfDay >= m_aTimeout ) + sal_uInt64 nTimeOfDay = tools::Time::GetMonotonicTicks(); + if( nTimeOfDay >= m_nTimeout ) { bRet = true; if( bExecuteTimers ) { // timed out, update timeout - m_aTimeout = aTimeOfDay; - m_aTimeout += m_nTimeoutMS; + m_nTimeout = nTimeOfDay; + m_nTimeout += m_nTimeoutMS*1000; osl::Guard< comphelper::SolarMutex > aGuard( GetYieldMutex() ); @@ -447,14 +445,12 @@ bool SvpSalInstance::ImplYield(bool bWait, bool bHandleAllCurrentEvents) sal_Int64 nTimeoutMicroS = 0; if (bMustSleep) { - if (m_aTimeout.tv_sec) // Timer is started. + if (m_nTimeout) // Timer is started. { - timeval Timeout; + sal_uInt64 nTimeout = tools::Time::GetMonotonicTicks(); // determine remaining timeout. - gettimeofday (&Timeout, nullptr); - if (m_aTimeout > Timeout) - nTimeoutMicroS = ((m_aTimeout.tv_sec - Timeout.tv_sec) * 1000 * 1000 + - (m_aTimeout.tv_usec - Timeout.tv_usec)); + if (m_nTimeout > nTimeout) + nTimeoutMicroS = m_nTimeout - nTimeout; } else nTimeoutMicroS = -1; // wait until something happens @@ -552,20 +548,19 @@ OUString SvpSalInstance::GetConnectionIdentifier() void SvpSalInstance::StopTimer() { - m_aTimeout.tv_sec = 0; - m_aTimeout.tv_usec = 0; - m_nTimeoutMS = 0; + m_nTimeout = 0; + m_nTimeoutMS = 0; } void SvpSalInstance::StartTimer( sal_uInt64 nMS ) { - timeval aPrevTimeout (m_aTimeout); - gettimeofday (&m_aTimeout, nullptr); + sal_uInt64 nPrevTimeout (m_nTimeout); + m_nTimeout = tools::Time::GetMonotonicTicks(); m_nTimeoutMS = nMS; - m_aTimeout += m_nTimeoutMS; + m_nTimeout += m_nTimeoutMS * 1000; - if ((aPrevTimeout > m_aTimeout) || (aPrevTimeout.tv_sec == 0)) + if ((nPrevTimeout > m_nTimeout) || (nPrevTimeout < 1000000)) { // Wakeup from previous timeout (or stopped timer). Wakeup(); diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx index e600259829b9..338776a88b6b 100644 --- a/vcl/inc/headless/svpinst.hxx +++ b/vcl/inc/headless/svpinst.hxx @@ -32,8 +32,6 @@ #include <mutex> #include <queue> -#include <sys/time.h> - #ifdef IOS #define SvpSalInstance AquaSalInstance #endif @@ -94,7 +92,7 @@ public: // (Wakeup is only called by SvpSalTimer and SvpSalFrame) class VCL_DLLPUBLIC SvpSalInstance : public SalGenericInstance, public SalUserEventList { - timeval m_aTimeout; + sal_uInt64 m_nTimeout; // in microseconds sal_uLong m_nTimeoutMS; oslThreadIdentifier m_MainThread;
