diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-07-22 22:32:35 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-07-23 12:25:56 +0200 |
commit | 2b2374c963bc660d8866bc17f701046ac0a03a3c (patch) | |
tree | 0f5cb239333eaec8c86c58b41d789f331baa62f2 | |
parent | 0de7513cd73f1f35265e42f9a2b9befe81302c2c (diff) |
simplify AsynchronLink
Change-Id: Ia13e256fcd0f332c4509ea4a9b47e1b050b56443
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119394
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/svtools/asynclink.hxx | 2 | ||||
-rw-r--r-- | svtools/source/control/asynclink.cxx | 49 |
2 files changed, 22 insertions, 29 deletions
diff --git a/include/svtools/asynclink.hxx b/include/svtools/asynclink.hxx index bc0c742a4b4e..3a699fe46a14 100644 --- a/include/svtools/asynclink.hxx +++ b/include/svtools/asynclink.hxx @@ -39,9 +39,7 @@ class UNLESS_MERGELIBS(SVT_DLLPUBLIC) AsynchronLink void* _pArg; std::mutex _aMutex; - DECL_DLLPRIVATE_LINK( HandleCall_Idle, Timer*, void ); DECL_DLLPRIVATE_LINK( HandleCall_PostUserEvent, void*, void ); - SVT_DLLPRIVATE void Call_Impl( void* pArg ); public: AsynchronLink( const Link<void*,void>& rLink ) diff --git a/svtools/source/control/asynclink.cxx b/svtools/source/control/asynclink.cxx index d1a111744691..e4faadfffc25 100644 --- a/svtools/source/control/asynclink.cxx +++ b/svtools/source/control/asynclink.cxx @@ -31,14 +31,14 @@ namespace svtools { void AsynchronLink::Call( void* pObj, bool bAllowDoubles ) { SAL_INFO_IF( !_bInCall, "svtools", "Recursives Call. Eher ueber Timer. TLX Fragen" ); // Do NOT translate. This is a valuable historical artefact. - if( _aLink.IsSet() ) - { - _pArg = pObj; - DBG_ASSERT( bAllowDoubles || !_nEventId, "Already made a call" ); - ClearPendingCall(); - std::lock_guard aGuard(_aMutex); - _nEventId = Application::PostUserEvent( LINK( this, AsynchronLink, HandleCall_PostUserEvent) ); - } + if( !_aLink.IsSet() ) + return; + + _pArg = pObj; + DBG_ASSERT( bAllowDoubles || !_nEventId, "Already made a call" ); + ClearPendingCall(); + std::lock_guard aGuard(_aMutex); + _nEventId = Application::PostUserEvent( LINK( this, AsynchronLink, HandleCall_PostUserEvent) ); } AsynchronLink::~AsynchronLink() @@ -47,23 +47,8 @@ AsynchronLink::~AsynchronLink() { Application::RemoveUserEvent( _nEventId ); } - if( _pDeleted ) *_pDeleted = true; -} - -IMPL_LINK_NOARG( AsynchronLink, HandleCall_Idle, Timer*, void ) -{ - { - std::lock_guard aGuard(_aMutex); - _nEventId = nullptr; - // need to release the lock before calling the client since - // the client may call back into us - } - Call_Impl( _pArg ); -} - -IMPL_LINK_NOARG( AsynchronLink, HandleCall_PostUserEvent, void*, void ) -{ - HandleCall_Idle(nullptr); + if( _pDeleted ) + *_pDeleted = true; } void AsynchronLink::ClearPendingCall() @@ -76,12 +61,22 @@ void AsynchronLink::ClearPendingCall() } } -void AsynchronLink::Call_Impl( void* pArg ) +IMPL_LINK_NOARG( AsynchronLink, HandleCall_PostUserEvent, void*, void ) { + { + std::lock_guard aGuard(_aMutex); + _nEventId = nullptr; + // need to release the lock before calling the client since + // the client may call back into us + } _bInCall = true; + + // some fancy footwork in case we get deleted inside the call bool bDeleted = false; _pDeleted = &bDeleted; - _aLink.Call( pArg ); + + _aLink.Call( _pArg ); + if( !bDeleted ) { _bInCall = false; |