[Libreoffice-commits] core.git: include/vcl vcl/source
Jan-Marek Glogowski
glogow at fbihome.de
Fri Jan 20 10:32:30 UTC 2017
include/vcl/idle.hxx | 2 +
include/vcl/scheduler.hxx | 9 ++++----
include/vcl/timer.hxx | 9 ++++++--
vcl/source/app/idle.cxx | 10 +++++++--
vcl/source/app/scheduler.cxx | 20 +++++++++---------
vcl/source/app/timer.cxx | 46 +++++++++++++++++++++++++++++++------------
6 files changed, 66 insertions(+), 30 deletions(-)
New commits:
commit 7cf3ae68afb9d3f2f126e544de85f38a18ad3de0
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Thu Jan 19 12:18:52 2017 +0100
Apply stricter member access control for Tasks
This disallows changing mbAuto and changing values of
ImplSchedulerData outside of Scheduler / Task functions.
Change-Id: Ia624999bd63190c072eb66427aec38e7ac8cfa1b
Reviewed-on: https://gerrit.libreoffice.org/33317
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>
diff --git a/include/vcl/idle.hxx b/include/vcl/idle.hxx
index 85ea758..8d79c2f 100644
--- a/include/vcl/idle.hxx
+++ b/include/vcl/idle.hxx
@@ -39,6 +39,8 @@ protected:
virtual bool IsIdle() const override;
virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const override;
+ Idle( bool bAuto, const sal_Char *pDebugName = nullptr );
+
public:
Idle( const sal_Char *pDebugName = nullptr );
diff --git a/include/vcl/scheduler.hxx b/include/vcl/scheduler.hxx
index dbe3128..19fbb4f 100644
--- a/include/vcl/scheduler.hxx
+++ b/include/vcl/scheduler.hxx
@@ -76,14 +76,16 @@ class VCL_DLLPUBLIC Task
friend class Scheduler;
friend struct ImplSchedulerData;
-protected:
ImplSchedulerData *mpSchedulerData; /// Pointer to the element in scheduler list
const sal_Char *mpDebugName; /// Useful for debugging
TaskPriority mePriority; /// Task priority
bool mbActive; /// Currently in the scheduler
+protected:
static void StartTimer( sal_uInt64 nMS );
+ inline const ImplSchedulerData* GetSchedulerData() const { return mpSchedulerData; }
+
virtual void SetDeletionFlags();
/// Is this item ready to be dispatched at nTimeNow
virtual bool ReadyForSchedule( bool bIdle, sal_uInt64 nTimeNow ) const = 0;
@@ -99,12 +101,13 @@ public:
Task( const sal_Char *pDebugName );
Task( const Task& rTask );
virtual ~Task();
+ Task& operator=( const Task& rTask );
void SetPriority(TaskPriority ePriority) { mePriority = ePriority; }
TaskPriority GetPriority() const { return mePriority; }
void SetDebugName( const sal_Char *pDebugName ) { mpDebugName = pDebugName; }
- const char *GetDebugName() { return mpDebugName; }
+ const char *GetDebugName() const { return mpDebugName; }
// Call handler
virtual void Invoke() = 0;
@@ -113,8 +116,6 @@ public:
void Stop();
bool IsActive() const { return mbActive; }
-
- Task& operator=( const Task& rTask );
};
#endif // INCLUDED_VCL_SCHEDULER_HXX
diff --git a/include/vcl/timer.hxx b/include/vcl/timer.hxx
index 07fb9a8..e7d539f 100644
--- a/include/vcl/timer.hxx
+++ b/include/vcl/timer.hxx
@@ -25,18 +25,23 @@
class VCL_DLLPUBLIC Timer : public Task
{
-protected:
Link<Timer *, void> maInvokeHandler; ///< Callback Link
sal_uInt64 mnTimeout;
- bool mbAuto;
+ const bool mbAuto;
+protected:
virtual void SetDeletionFlags() override;
virtual bool ReadyForSchedule( bool bIdle, sal_uInt64 nTimeNow ) const override;
virtual bool IsIdle() const override;
virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const override;
+ Timer( bool bAuto, const sal_Char *pDebugName = nullptr );
+
public:
Timer( const sal_Char *pDebugName = nullptr );
+ Timer( const Timer& rTimer );
+ virtual ~Timer() override;
+ Timer& operator=( const Timer& rTimer );
/**
* Calls the maInvokeHandler with the parameter this.
diff --git a/vcl/source/app/idle.cxx b/vcl/source/app/idle.cxx
index 895000a..a086b5f 100644
--- a/vcl/source/app/idle.cxx
+++ b/vcl/source/app/idle.cxx
@@ -20,8 +20,14 @@
#include <vcl/idle.hxx>
#include "saltimer.hxx"
+Idle::Idle( bool bAuto, const sal_Char *pDebugName )
+ : Timer( bAuto, pDebugName )
+{
+ SetPriority( TaskPriority::DEFAULT_IDLE );
+}
+
Idle::Idle( const sal_Char *pDebugName )
- : Timer( pDebugName )
+ : Idle( false, pDebugName )
{
}
@@ -32,7 +38,7 @@ void Idle::Start()
sal_uInt64 nPeriod = Scheduler::ImmediateTimeoutMs;
if (Scheduler::GetDeterministicMode())
{
- switch (mePriority)
+ switch ( GetPriority() )
{
case TaskPriority::LOW:
case TaskPriority::LOWER:
diff --git a/vcl/source/app/scheduler.cxx b/vcl/source/app/scheduler.cxx
index 3a62f3d..d13ad3e 100644
--- a/vcl/source/app/scheduler.cxx
+++ b/vcl/source/app/scheduler.cxx
@@ -334,19 +334,19 @@ Task& Task::operator=( const Task& rTask )
return *this;
}
-Task::Task(const sal_Char *pDebugName):
- mpSchedulerData(nullptr),
- mpDebugName(pDebugName),
- mePriority(TaskPriority::HIGH),
- mbActive(false)
+Task::Task( const sal_Char *pDebugName )
+ : mpSchedulerData( nullptr )
+ , mpDebugName( pDebugName )
+ , mePriority( TaskPriority::HIGH )
+ , mbActive( false )
{
}
-Task::Task( const Task& rTask ):
- mpSchedulerData(nullptr),
- mpDebugName(rTask.mpDebugName),
- mePriority(rTask.mePriority),
- mbActive(false)
+Task::Task( const Task& rTask )
+ : mpSchedulerData( nullptr )
+ , mpDebugName( rTask.mpDebugName )
+ , mePriority( rTask.mePriority )
+ , mbActive( false )
{
if ( rTask.IsActive() )
Start();
diff --git a/vcl/source/app/timer.cxx b/vcl/source/app/timer.cxx
index 77704db..56f0922 100644
--- a/vcl/source/app/timer.cxx
+++ b/vcl/source/app/timer.cxx
@@ -25,15 +25,12 @@ void Timer::SetDeletionFlags()
{
// If no AutoTimer, then stop.
if ( !mbAuto )
- {
- mpSchedulerData->mbDelete = true;
- mbActive = false;
- }
+ Task::SetDeletionFlags();
}
bool Timer::ReadyForSchedule( bool /* bIdle */, sal_uInt64 nTimeNow ) const
{
- return (mpSchedulerData->mnUpdateTime + mnTimeout) <= nTimeNow;
+ return (GetSchedulerData()->mnUpdateTime + mnTimeout) <= nTimeNow;
}
bool Timer::IsIdle() const
@@ -43,7 +40,7 @@ bool Timer::IsIdle() const
sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const
{
- sal_uInt64 nWakeupTime = mpSchedulerData->mnUpdateTime + mnTimeout;
+ sal_uInt64 nWakeupTime = GetSchedulerData()->mnUpdateTime + mnTimeout;
if( nWakeupTime <= nTimeNow )
return Scheduler::ImmediateTimeoutMs;
else
@@ -53,12 +50,38 @@ sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow )
}
}
-Timer::Timer(const sal_Char *pDebugName)
+Timer::Timer( bool bAuto, const sal_Char *pDebugName )
: Task( pDebugName )
, mnTimeout( Scheduler::ImmediateTimeoutMs )
- , mbAuto( false )
+ , mbAuto( bAuto )
+{
+ SetPriority( TaskPriority::HIGHEST );
+}
+
+Timer::Timer( const sal_Char *pDebugName )
+ : Timer( false, pDebugName )
+{
+}
+
+Timer::Timer( const Timer& rTimer )
+ : Timer( rTimer.mbAuto, rTimer.GetDebugName() )
+{
+ maInvokeHandler = rTimer.maInvokeHandler;
+ mnTimeout = rTimer.mnTimeout;
+}
+
+Timer::~Timer()
+{
+}
+
+Timer& Timer::operator=( const Timer& rTimer )
{
- mePriority = TaskPriority::HIGHEST;
+ Task::operator=( rTimer );
+ maInvokeHandler = rTimer.maInvokeHandler;
+ mnTimeout = rTimer.mnTimeout;
+ SAL_WARN_IF( mbAuto != rTimer.mbAuto, "vcl.schedule",
+ "Copying Timer with different mbAuto value!" );
+ return *this;
}
void Timer::Invoke()
@@ -81,14 +104,13 @@ void Timer::SetTimeout( sal_uInt64 nNewTimeout )
{
mnTimeout = nNewTimeout;
// If timer is active, then renew clock.
- if ( mbActive )
+ if ( IsActive() )
StartTimer( mnTimeout );
}
AutoTimer::AutoTimer( const sal_Char *pDebugName )
- : Timer( pDebugName )
+ : Timer( true, pDebugName )
{
- mbAuto = true;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list