From b34786d2774b261be48de92f65a5d0aa3c32b289 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Wed, 17 Apr 2019 16:23:39 +0100 Subject: Unipoll: add LibreOfficeKit API for polling, and an option to use it. Change-Id: Iee7556ee52541ddbf1ef8f31e1ed4697f805a2ac Reviewed-on: https://gerrit.libreoffice.org/70898 Tested-by: Jenkins Reviewed-by: Ashod Nakashian --- vcl/headless/svpinst.cxx | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'vcl/headless') diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx index 324d976cb95e..69353b104fc3 100644 --- a/vcl/headless/svpinst.cxx +++ b/vcl/headless/svpinst.cxx @@ -51,6 +51,7 @@ #include // FIXME: remove when we re-work the svp mainloop #include +#include SvpSalInstance* SvpSalInstance::s_pDefaultInstance = nullptr; @@ -175,12 +176,15 @@ void SvpSalInstance::Wakeup(SvpRequest const request) #ifdef IOS (void)request; #else + ImplSVData* pSVData = ImplGetSVData(); + + if (pSVData->mpWakeCallback) + pSVData->mpWakeCallback(pSVData->mpPollClosure); + SvpSalYieldMutex *const pMutex(static_cast(GetYieldMutex())); std::unique_lock g(pMutex->m_WakeUpMainMutex); if (request != SvpRequest::NONE) - { pMutex->m_Request = request; - } pMutex->m_wakeUpMain = true; pMutex->m_WakeUpMainCond.notify_one(); #endif @@ -373,11 +377,8 @@ sal_uInt32 SvpSalYieldMutex::doRelease(bool const bUnlockAll) // read m_nCount before doRelease bool const isReleased(bUnlockAll || m_nCount == 1); nCount = comphelper::SolarMutex::doRelease( bUnlockAll ); - if (isReleased) { - std::unique_lock g(m_WakeUpMainMutex); - m_wakeUpMain = true; - m_WakeUpMainCond.notify_one(); - } + if (isReleased && pInst) + pInst->Wakeup(SvpRequest::NONE); } return nCount; } @@ -420,8 +421,8 @@ bool SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents) #endif // first, process current user events - bool bEvent = DispatchUserEvents( bHandleAllCurrentEvents ); - if ( !bHandleAllCurrentEvents && bEvent ) + bool bEvent = DispatchUserEvents(bHandleAllCurrentEvents); + if (!bHandleAllCurrentEvents && bEvent) return true; bEvent = CheckTimeout() || bEvent; @@ -450,7 +451,20 @@ bool SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents) else nTimeoutMS = -1; // wait until something happens + ImplSVData* pSVData = ImplGetSVData(); sal_uInt32 nAcquireCount = ReleaseYieldMutexAll(); + + if (pSVData->mpPollCallback) + { + // Poll for events from the LOK client. + if (nTimeoutMS < 0) + nTimeoutMS = 5000; + + // External poll. + if (pSVData->mpPollCallback(pSVData->mpPollClosure, nTimeoutMS * 1000 /* us */) < 0) + pSVData->maAppData.mbAppQuit = true; + } + else { std::unique_lock g(pMutex->m_WakeUpMainMutex); // wait for doRelease() or Wakeup() to set the condition -- cgit