diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-19 13:19:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-20 08:51:08 +0200 |
commit | 46a0ce80326a44bd13e3483106dd0e9bf32a7824 (patch) | |
tree | dd6858fbef8359bbaf7b91e52e4fc1b7b77e96be /chart2 | |
parent | cef8ebe925bde6fc1889085e3ccb1be236791e99 (diff) |
use rtl::Reference in TheModelRef
instead of manual acquire/release
Change-Id: I7a5ae0337fc8fa1465ac716050e7187aa1accb87
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/controller/inc/ChartController.hxx | 6 | ||||
-rw-r--r-- | chart2/source/controller/main/ChartController.cxx | 30 |
2 files changed, 9 insertions, 27 deletions
diff --git a/chart2/source/controller/inc/ChartController.hxx b/chart2/source/controller/inc/ChartController.hxx index 3b3449170eec..eb2ba8857696 100644 --- a/chart2/source/controller/inc/ChartController.hxx +++ b/chart2/source/controller/inc/ChartController.hxx @@ -414,10 +414,10 @@ private: TheModelRef& operator=(const TheModelRef& rTheModel); ~TheModelRef(); bool is() const; - TheModel* operator->() const { return m_pTheModel; } + TheModel* operator->() const { return m_xTheModel.get(); } private: - TheModel* m_pTheModel; - ::osl::Mutex& m_rModelMutex; + rtl::Reference<TheModel> m_xTheModel; + ::osl::Mutex& m_rModelMutex; }; private: diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx index 0233edbbd7b2..8c331a2fe484 100644 --- a/chart2/source/controller/main/ChartController.cxx +++ b/chart2/source/controller/main/ChartController.cxx @@ -221,55 +221,37 @@ void ChartController::TheModel::tryTermination() } ChartController::TheModelRef::TheModelRef( TheModel* pTheModel, osl::Mutex& rMutex ) : - m_pTheModel(pTheModel), m_rModelMutex(rMutex) { osl::Guard< osl::Mutex > aGuard( m_rModelMutex ); - if(m_pTheModel) - m_pTheModel->acquire(); + m_xTheModel = pTheModel; } ChartController::TheModelRef::TheModelRef( const TheModelRef& rTheModel, ::osl::Mutex& rMutex ) : m_rModelMutex(rMutex) { osl::Guard< osl::Mutex > aGuard( m_rModelMutex ); - m_pTheModel=rTheModel.operator->(); - if(m_pTheModel) - m_pTheModel->acquire(); + m_xTheModel = rTheModel.m_xTheModel; } ChartController::TheModelRef& ChartController::TheModelRef::operator=(TheModel* pTheModel) { osl::Guard< osl::Mutex > aGuard( m_rModelMutex ); - if(m_pTheModel==pTheModel) - return *this; - if(m_pTheModel) - m_pTheModel->release(); - m_pTheModel=pTheModel; - if(m_pTheModel) - m_pTheModel->acquire(); + m_xTheModel = pTheModel; return *this; } ChartController::TheModelRef& ChartController::TheModelRef::operator=(const TheModelRef& rTheModel) { osl::Guard< osl::Mutex > aGuard( m_rModelMutex ); - TheModel* pNew=rTheModel.operator->(); - if(m_pTheModel==pNew) - return *this; - if(m_pTheModel) - m_pTheModel->release(); - m_pTheModel=pNew; - if(m_pTheModel) - m_pTheModel->acquire(); + m_xTheModel = rTheModel.operator->(); return *this; } ChartController::TheModelRef::~TheModelRef() { osl::Guard< osl::Mutex > aGuard( m_rModelMutex ); - if(m_pTheModel) - m_pTheModel->release(); + m_xTheModel.clear(); } bool ChartController::TheModelRef::is() const { - return (m_pTheModel != nullptr); + return m_xTheModel.is(); } namespace { |