diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-09-29 21:02:17 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-10-04 14:53:33 +0200 |
commit | da5cdcdeddf7bc21606b4cb64d8b1fc412146935 (patch) | |
tree | e887175264e671a241e735763100e40adaa15e7c /vcl/inc | |
parent | 96e67461c8b451f3a313bcc973ac49c5e49537c0 (diff) |
Convert tick-based timer events to versioned ones
Instead of storing the system ticks in the timer event message
simply store a version.
Moves the version handling code into a VersionedEvent class,
inherited by WinSalTimer and AquaSalTimer.
Change-Id: I5add85031d36b3424a26a9ef798294cbfb00b2e4
Reviewed-on: https://gerrit.libreoffice.org/42959
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/inc')
-rw-r--r-- | vcl/inc/osx/saltimer.h | 3 | ||||
-rw-r--r-- | vcl/inc/saltimer.hxx | 44 | ||||
-rw-r--r-- | vcl/inc/win/saltimer.h | 7 |
3 files changed, 49 insertions, 5 deletions
diff --git a/vcl/inc/osx/saltimer.h b/vcl/inc/osx/saltimer.h index f70bd65491b8..65247b930cfa 100644 --- a/vcl/inc/osx/saltimer.h +++ b/vcl/inc/osx/saltimer.h @@ -41,10 +41,9 @@ public: ~ReleasePoolHolder() { [mpPool release]; } }; -class AquaSalTimer : public SalTimer +class AquaSalTimer final : public SalTimer, protected VersionedEvent { NSTimer *m_pRunningTimer; - sal_Int32 m_nTimerStartTicks; ///< system ticks at timer start % SAL_MAX_INT32 void queueDispatchTimerEvent( bool bAtStart ); void callTimerCallback(); diff --git a/vcl/inc/saltimer.hxx b/vcl/inc/saltimer.hxx index e0179dd5fd27..983e0771ee9b 100644 --- a/vcl/inc/saltimer.hxx +++ b/vcl/inc/saltimer.hxx @@ -34,6 +34,7 @@ class VCL_PLUGIN_PUBLIC SalTimer { SALTIMERPROC m_pProc; + public: SalTimer() : m_pProc( nullptr ) {} virtual ~SalTimer() COVERITY_NOEXCEPT_FALSE; @@ -55,6 +56,49 @@ public: } }; +class VersionedEvent +{ + /** + * The "additional event data" members on macOS are integers, so we can't + * use an unsigned integer and rely on the defined unsigned overflow in + * InvalidateEvent(). + */ + sal_Int32 m_nEventVersion; + bool m_bIsValidVersion; + +public: + VersionedEvent() : m_nEventVersion( 0 ), m_bIsValidVersion( false ) {} + + sal_Int32 GetNextEventVersion() + { + InvalidateEvent(); + m_bIsValidVersion = true; + return m_nEventVersion; + } + + void InvalidateEvent() + { + if ( m_bIsValidVersion ) + { + if ( m_nEventVersion == SAL_MAX_INT32 ) + m_nEventVersion = 0; + else + ++m_nEventVersion; + m_bIsValidVersion = false; + } + } + + bool ExistsValidEvent() const + { + return m_bIsValidVersion; + } + + bool IsValidEventVersion( const sal_Int32 nEventVersion ) const + { + return m_bIsValidVersion && nEventVersion == m_nEventVersion; + } +}; + #endif // INCLUDED_VCL_INC_SALTIMER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/win/saltimer.h b/vcl/inc/win/saltimer.h index f87361e55ed8..06e77b171cb3 100644 --- a/vcl/inc/win/saltimer.h +++ b/vcl/inc/win/saltimer.h @@ -22,13 +22,14 @@ #include <saltimer.hxx> -class WinSalTimer : public SalTimer +class WinSalTimer final : public SalTimer, protected VersionedEvent { // for access to Impl* functions friend LRESULT CALLBACK SalComWndProc( HWND, UINT nMsg, WPARAM wParam, LPARAM lParam, int& rDef ); + // for access to m_bPollForMessage + friend static void CALLBACK SalTimerProc( PVOID data, BOOLEAN ); HANDLE m_nTimerId; ///< Windows timer id - sal_uInt32 m_nTimerStartTicks; ///< system ticks at timer start % SAL_MAX_UINT32 bool m_bPollForMessage; ///< Run yield until a message is caught (most likely the 0ms timer) void ImplStart( sal_uIntPtr nMS ); @@ -49,7 +50,7 @@ public: inline bool WinSalTimer::IsValidWPARAM( WPARAM aWPARAM ) const { - return aWPARAM == m_nTimerStartTicks; + return IsValidEventVersion( static_cast<sal_Int32>( aWPARAM ) ); } inline bool WinSalTimer::PollForMessage() const |