use rtl::Reference in OContainerListener

instead of manual acquire/release

Change-Id: I83e6229029e662073e2e01e98f4846fb0a0ed643
This commit is contained in:
Noel Grandin
2017-01-19 16:02:25 +02:00
parent 3663edf465
commit 3bb8bdb93f
2 changed files with 8 additions and 20 deletions

View File

@@ -29,18 +29,16 @@ namespace comphelper
using namespace ::com::sun::star::container; using namespace ::com::sun::star::container;
OContainerListener::OContainerListener(::osl::Mutex& _rMutex) OContainerListener::OContainerListener(::osl::Mutex& _rMutex)
:m_pAdapter(nullptr) :m_rMutex(_rMutex)
,m_rMutex(_rMutex)
{ {
} }
OContainerListener::~OContainerListener() OContainerListener::~OContainerListener()
{ {
if (m_pAdapter) if (m_xAdapter.is())
{ {
m_pAdapter->dispose(); m_xAdapter->dispose();
m_pAdapter = nullptr;
} }
} }
@@ -71,19 +69,8 @@ namespace comphelper
void OContainerListener::setAdapter(OContainerListenerAdapter* pAdapter) void OContainerListener::setAdapter(OContainerListenerAdapter* pAdapter)
{ {
if (m_pAdapter) ::osl::MutexGuard aGuard(m_rMutex);
{ m_xAdapter = pAdapter;
::osl::MutexGuard aGuard(m_rMutex);
m_pAdapter->release();
m_pAdapter = nullptr;
}
if (pAdapter)
{
::osl::MutexGuard aGuard(m_rMutex);
m_pAdapter = pAdapter;
m_pAdapter->acquire();
}
} }
OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener* _pListener, OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener* _pListener,

View File

@@ -24,6 +24,7 @@
#include <cppuhelper/implbase.hxx> #include <cppuhelper/implbase.hxx>
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <comphelper/comphelperdllapi.h> #include <comphelper/comphelperdllapi.h>
#include <rtl/ref.hxx>
namespace comphelper namespace comphelper
@@ -43,8 +44,8 @@ namespace comphelper
{ {
friend class OContainerListenerAdapter; friend class OContainerListenerAdapter;
protected: protected:
OContainerListenerAdapter* m_pAdapter; rtl::Reference<OContainerListenerAdapter> m_xAdapter;
::osl::Mutex& m_rMutex; ::osl::Mutex& m_rMutex;
public: public:
OContainerListener(::osl::Mutex& _rMutex); OContainerListener(::osl::Mutex& _rMutex);