Introduce vcl::lok::unregisterPollCallbacks() and clarify isUnipoll()

There was a problem in the iOS app where a callback was done passing a
registered mpPollClosure that pointed to the mainKit variable in
lokit_main() even though that variable had already gone out of scope
and been destructed.

Introduce unregisterPollCallbacks(), which just sets the mpPollClosure
pointer to null. That means no callbacks should be done any more. It
does not mean that Unipoll would not be active. Change isUnipoll() to
look at whether the mpPollCallback pointer has been set or not.

Change-Id: I5d5527c0ef097682679371dc642f8896ff05450d
Reviewed-on: https://gerrit.libreoffice.org/72283
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
This commit is contained in:
Tor Lillqvist
2019-05-16 13:24:42 +03:00
parent b27755b704
commit e10cd7b8bf
3 changed files with 20 additions and 5 deletions
+1
View File
@@ -21,6 +21,7 @@ namespace lok
bool VCL_DLLPUBLIC isUnipoll();
void VCL_DLLPUBLIC registerPollCallbacks(LibreOfficeKitPollCallback pPollCallback,
LibreOfficeKitWakeCallback pWakeCallback, void* pData);
void VCL_DLLPUBLIC unregisterPollCallbacks();
}
}
+5 -4
View File
@@ -29,6 +29,7 @@
#include <vcl/virdev.hxx>
#include <vcl/inputtypes.hxx>
#include <vcl/lok.hxx>
#ifndef LIBO_HEADLESS
# include <vcl/opengl/OpenGLContext.hxx>
#endif
@@ -176,7 +177,7 @@ void SvpSalInstance::Wakeup(SvpRequest const request)
ImplSVData* pSVData = ImplGetSVData();
if (pSVData->mpWakeCallback)
if (pSVData->mpWakeCallback && pSVData->mpPollClosure)
pSVData->mpWakeCallback(pSVData->mpPollClosure);
SvpSalYieldMutex *const pMutex(static_cast<SvpSalYieldMutex*>(GetYieldMutex()));
@@ -377,8 +378,7 @@ sal_uInt32 SvpSalYieldMutex::doRelease(bool const bUnlockAll)
if (isReleased)
{
ImplSVData* pSVData = ImplGetSVData();
if (pSVData->mpPollCallback) // is unipoll
if (vcl::lok::isUnipoll())
{
if (pInst)
pInst->Wakeup(SvpRequest::NONE);
@@ -472,7 +472,8 @@ bool SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents)
nTimeoutMS = 5000;
// External poll.
if (pSVData->mpPollCallback(pSVData->mpPollClosure, nTimeoutMS * 1000 /* us */) < 0)
if (pSVData->mpPollClosure != nullptr &&
pSVData->mpPollCallback(pSVData->mpPollClosure, nTimeoutMS * 1000 /* us */) < 0)
pSVData->maAppData.mbAppQuit = true;
}
else
+14 -1
View File
@@ -1675,10 +1675,23 @@ void registerPollCallbacks(
}
}
void unregisterPollCallbacks()
{
ImplSVData * pSVData = ImplGetSVData();
if (pSVData)
{
// Just set mpPollClosure to null as that is what calling this means, that the callback data
// points to an object that no longer exists. In particular, don't set
// pSVData->mpPollCallback to nullptr as that is used to detect whether Unipoll is in use in
// isUnipoll().
pSVData->mpPollClosure = nullptr;
}
}
bool isUnipoll()
{
ImplSVData * pSVData = ImplGetSVData();
return pSVData && pSVData->mpPollClosure != nullptr;
return pSVData && pSVData->mpPollCallback != nullptr;
}
} } // namespace lok, namespace vcl