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 <caolan.mcnamara@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196954
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist <tml@iki.fi>
This commit is contained in:
Tor Lillqvist
2026-01-10 16:19:15 +01:00
parent 03bab8b877
commit 0a5bf9517a
2 changed files with 21 additions and 28 deletions
+20 -25
View File
@@ -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
@@ -90,9 +90,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 )
@@ -152,18 +151,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() );
@@ -459,14 +457,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
@@ -559,20 +555,19 @@ bool SvpSalInstance::AnyInput( VclInputFlags nType )
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();
+1 -3
View File
@@ -31,8 +31,6 @@
#include <mutex>
#include <queue>
#include <sys/time.h>
#ifdef IOS
#define SvpSalInstance AquaSalInstance
#endif
@@ -90,7 +88,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;