Kaydet (Commit) 6a95ebee authored tarafından Tor Lillqvist's avatar Tor Lillqvist Kaydeden (comit) Michael Meeks

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/72283Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 3f329e4a
...@@ -21,6 +21,7 @@ namespace lok ...@@ -21,6 +21,7 @@ namespace lok
bool VCL_DLLPUBLIC isUnipoll(); bool VCL_DLLPUBLIC isUnipoll();
void VCL_DLLPUBLIC registerPollCallbacks(LibreOfficeKitPollCallback pPollCallback, void VCL_DLLPUBLIC registerPollCallbacks(LibreOfficeKitPollCallback pPollCallback,
LibreOfficeKitWakeCallback pWakeCallback, void* pData); LibreOfficeKitWakeCallback pWakeCallback, void* pData);
void VCL_DLLPUBLIC unregisterPollCallbacks();
} }
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <sal/types.h> #include <sal/types.h>
#include <vcl/inputtypes.hxx> #include <vcl/inputtypes.hxx>
#include <vcl/lok.hxx>
#ifndef LIBO_HEADLESS #ifndef LIBO_HEADLESS
# include <vcl/opengl/OpenGLContext.hxx> # include <vcl/opengl/OpenGLContext.hxx>
#endif #endif
...@@ -165,7 +166,7 @@ void SvpSalInstance::Wakeup(SvpRequest const request) ...@@ -165,7 +166,7 @@ void SvpSalInstance::Wakeup(SvpRequest const request)
ImplSVData* pSVData = ImplGetSVData(); ImplSVData* pSVData = ImplGetSVData();
if (pSVData->mpWakeCallback) if (pSVData->mpWakeCallback && pSVData->mpPollClosure)
pSVData->mpWakeCallback(pSVData->mpPollClosure); pSVData->mpWakeCallback(pSVData->mpPollClosure);
SvpSalYieldMutex *const pMutex(static_cast<SvpSalYieldMutex*>(mpSalYieldMutex.get())); SvpSalYieldMutex *const pMutex(static_cast<SvpSalYieldMutex*>(mpSalYieldMutex.get()));
...@@ -354,8 +355,7 @@ sal_uInt32 SvpSalYieldMutex::doRelease(bool const bUnlockAll) ...@@ -354,8 +355,7 @@ sal_uInt32 SvpSalYieldMutex::doRelease(bool const bUnlockAll)
nCount = comphelper::GenericSolarMutex::doRelease( bUnlockAll ); nCount = comphelper::GenericSolarMutex::doRelease( bUnlockAll );
if (isReleased) if (isReleased)
{ {
ImplSVData* pSVData = ImplGetSVData(); if (vcl::lok::isUnipoll())
if (pSVData->mpPollCallback) // is unipoll
{ {
if (pInst) if (pInst)
pInst->Wakeup(SvpRequest::NONE); pInst->Wakeup(SvpRequest::NONE);
...@@ -450,7 +450,8 @@ bool SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents) ...@@ -450,7 +450,8 @@ bool SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents)
nTimeoutMS = 5000; nTimeoutMS = 5000;
// External poll. // 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; pSVData->maAppData.mbAppQuit = true;
} }
else else
......
...@@ -1727,10 +1727,23 @@ void registerPollCallbacks( ...@@ -1727,10 +1727,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() bool isUnipoll()
{ {
ImplSVData * pSVData = ImplGetSVData(); ImplSVData * pSVData = ImplGetSVData();
return pSVData && pSVData->mpPollClosure != nullptr; return pSVData && pSVData->mpPollCallback != nullptr;
} }
} } // namespace lok, namespace vcl } } // namespace lok, namespace vcl
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment