Use an osl::Mutex directly

Change-Id: Icb655df89fcb3c9dac0f25d0fdb5383d24914877
This commit is contained in:
Stephan Bergmann
2014-03-20 11:37:15 +01:00
parent ed15977626
commit 4f843f2bc8
2 changed files with 30 additions and 54 deletions

View File

@@ -27,7 +27,6 @@
// include files of own module // include files of own module
#include <helper/wakeupthread.hxx> #include <helper/wakeupthread.hxx>
#include <threadhelp/threadhelpbase.hxx>
#include <macros/xinterface.hxx> #include <macros/xinterface.hxx>
#include <macros/xtypeprovider.hxx> #include <macros/xtypeprovider.hxx>
#include <macros/xserviceinfo.hxx> #include <macros/xserviceinfo.hxx>
@@ -151,8 +150,7 @@ typedef ::std::vector< IndicatorInfo > IndicatorStack;
@devstatus ready to use @devstatus ready to use
@threadsafe yes @threadsafe yes
*/ */
class StatusIndicatorFactory : private ThreadHelpBase class StatusIndicatorFactory : public ::cppu::WeakImplHelper4<
, public ::cppu::WeakImplHelper4<
css::lang::XServiceInfo css::lang::XServiceInfo
, css::lang::XInitialization , css::lang::XInitialization
, css::task::XStatusIndicatorFactory , css::task::XStatusIndicatorFactory
@@ -161,6 +159,7 @@ class StatusIndicatorFactory : private ThreadHelpBase
// member // member
private: private:
osl::Mutex m_mutex;
/** stack with all current indicator children. */ /** stack with all current indicator children. */
IndicatorStack m_aStack; IndicatorStack m_aStack;

View File

@@ -55,8 +55,7 @@ const char PROGRESS_RESOURCE[] = "private:resource/progressbar/progressbar";
StatusIndicatorFactory::StatusIndicatorFactory(const css::uno::Reference< css::uno::XComponentContext >& xContext) StatusIndicatorFactory::StatusIndicatorFactory(const css::uno::Reference< css::uno::XComponentContext >& xContext)
: ThreadHelpBase ( ) : m_xContext (xContext )
, m_xContext (xContext )
, m_pWakeUp (0 ) , m_pWakeUp (0 )
, m_bAllowReschedule (sal_False) , m_bAllowReschedule (sal_False)
, m_bAllowParentShow (sal_False) , m_bAllowParentShow (sal_False)
@@ -76,8 +75,7 @@ void SAL_CALL StatusIndicatorFactory::initialize(const css::uno::Sequence< css::
css::uno::RuntimeException, std::exception) css::uno::RuntimeException, std::exception)
{ {
if (lArguments.getLength() > 0) { if (lArguments.getLength() > 0) {
// SAFE -> ---------------------------------- osl::MutexGuard g(m_mutex);
Guard aWriteLock(m_aLock);
css::uno::Reference< css::frame::XFrame > xTmpFrame; css::uno::Reference< css::frame::XFrame > xTmpFrame;
css::uno::Reference< css::awt::XWindow > xTmpWindow; css::uno::Reference< css::awt::XWindow > xTmpWindow;
@@ -101,9 +99,6 @@ void SAL_CALL StatusIndicatorFactory::initialize(const css::uno::Sequence< css::
m_xPluggWindow = lArgs.getUnpackedValueOrDefault("Window" , css::uno::Reference< css::awt::XWindow >() ); m_xPluggWindow = lArgs.getUnpackedValueOrDefault("Window" , css::uno::Reference< css::awt::XWindow >() );
m_bAllowParentShow = lArgs.getUnpackedValueOrDefault("AllowParentShow" , (sal_Bool)sal_False ); m_bAllowParentShow = lArgs.getUnpackedValueOrDefault("AllowParentShow" , (sal_Bool)sal_False );
m_bDisableReschedule = lArgs.getUnpackedValueOrDefault("DisableReschedule", (sal_Bool)sal_False ); m_bDisableReschedule = lArgs.getUnpackedValueOrDefault("DisableReschedule", (sal_Bool)sal_False );
aWriteLock.unlock();
// <- SAFE ----------------------------------
} }
} }
@@ -124,11 +119,8 @@ css::uno::Reference< css::task::XStatusIndicator > SAL_CALL StatusIndicatorFacto
void SAL_CALL StatusIndicatorFactory::update() void SAL_CALL StatusIndicatorFactory::update()
throw(css::uno::RuntimeException, std::exception) throw(css::uno::RuntimeException, std::exception)
{ {
// SAFE -> ---------------------------------- osl::MutexGuard g(m_mutex);
Guard aWriteLock(m_aLock);
m_bAllowReschedule = sal_True; m_bAllowReschedule = sal_True;
aWriteLock.unlock();
// <- SAFE ----------------------------------
} }
@@ -137,7 +129,7 @@ void StatusIndicatorFactory::start(const css::uno::Reference< css::task::XStatus
sal_Int32 nRange) sal_Int32 nRange)
{ {
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
Guard aWriteLock(m_aLock); osl::ClearableMutexGuard aWriteLock(m_mutex);
// create new info structure for this child or move it to the front of our stack // create new info structure for this child or move it to the front of our stack
IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild); IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
@@ -149,7 +141,7 @@ void StatusIndicatorFactory::start(const css::uno::Reference< css::task::XStatus
m_xActiveChild = xChild; m_xActiveChild = xChild;
css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress; css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
aWriteLock.unlock(); aWriteLock.clear();
// <- SAFE ---------------------------------- // <- SAFE ----------------------------------
implts_makeParentVisibleIfAllowed(); implts_makeParentVisibleIfAllowed();
@@ -165,7 +157,7 @@ void StatusIndicatorFactory::start(const css::uno::Reference< css::task::XStatus
void StatusIndicatorFactory::reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild) void StatusIndicatorFactory::reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild)
{ {
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
Guard aReadLock(m_aLock); osl::ClearableMutexGuard aReadLock(m_mutex);
// reset the internal info structure related to this child // reset the internal info structure related to this child
IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild); IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
@@ -178,7 +170,7 @@ void StatusIndicatorFactory::reset(const css::uno::Reference< css::task::XStatus
css::uno::Reference< css::task::XStatusIndicator > xActive = m_xActiveChild; css::uno::Reference< css::task::XStatusIndicator > xActive = m_xActiveChild;
css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress; css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
aReadLock.unlock(); aReadLock.clear();
// <- SAFE ---------------------------------- // <- SAFE ----------------------------------
// not the top most child => dont change UI // not the top most child => dont change UI
@@ -196,7 +188,7 @@ void StatusIndicatorFactory::reset(const css::uno::Reference< css::task::XStatus
void StatusIndicatorFactory::end(const css::uno::Reference< css::task::XStatusIndicator >& xChild) void StatusIndicatorFactory::end(const css::uno::Reference< css::task::XStatusIndicator >& xChild)
{ {
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
Guard aWriteLock(m_aLock); osl::ClearableMutexGuard aWriteLock(m_mutex);
// remove this child from our stack // remove this child from our stack
IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild); IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
@@ -218,7 +210,7 @@ void StatusIndicatorFactory::end(const css::uno::Reference< css::task::XStatusIn
css::uno::Reference< css::task::XStatusIndicator > xActive = m_xActiveChild; css::uno::Reference< css::task::XStatusIndicator > xActive = m_xActiveChild;
css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress; css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
aWriteLock.unlock(); aWriteLock.clear();
// <- SAFE ---------------------------------- // <- SAFE ----------------------------------
if (xActive.is()) if (xActive.is())
@@ -251,7 +243,7 @@ void StatusIndicatorFactory::setText(const css::uno::Reference< css::task::XStat
const OUString& sText ) const OUString& sText )
{ {
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
Guard aWriteLock(m_aLock); osl::ClearableMutexGuard aWriteLock(m_mutex);
IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild); IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
if (pItem != m_aStack.end()) if (pItem != m_aStack.end())
@@ -260,7 +252,7 @@ void StatusIndicatorFactory::setText(const css::uno::Reference< css::task::XStat
css::uno::Reference< css::task::XStatusIndicator > xActive = m_xActiveChild; css::uno::Reference< css::task::XStatusIndicator > xActive = m_xActiveChild;
css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress; css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
aWriteLock.unlock(); aWriteLock.clear();
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
// paint only the top most indicator // paint only the top most indicator
@@ -281,7 +273,7 @@ void StatusIndicatorFactory::setValue( const css::uno::Reference< css::task::XSt
sal_Int32 nValue ) sal_Int32 nValue )
{ {
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
Guard aWriteLock(m_aLock); osl::ClearableMutexGuard aWriteLock(m_mutex);
sal_Int32 nOldValue = 0; sal_Int32 nOldValue = 0;
IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild); IndicatorStack::iterator pItem = ::std::find(m_aStack.begin(), m_aStack.end(), xChild);
@@ -294,7 +286,7 @@ void StatusIndicatorFactory::setValue( const css::uno::Reference< css::task::XSt
css::uno::Reference< css::task::XStatusIndicator > xActive = m_xActiveChild; css::uno::Reference< css::task::XStatusIndicator > xActive = m_xActiveChild;
css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress; css::uno::Reference< css::task::XStatusIndicator > xProgress = m_xProgress;
aWriteLock.unlock(); aWriteLock.clear();
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
if ( if (
@@ -313,7 +305,7 @@ void StatusIndicatorFactory::setValue( const css::uno::Reference< css::task::XSt
void StatusIndicatorFactory::implts_makeParentVisibleIfAllowed() void StatusIndicatorFactory::implts_makeParentVisibleIfAllowed()
{ {
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
Guard aReadLock(m_aLock); osl::ClearableMutexGuard aReadLock(m_mutex);
if (!m_bAllowParentShow) if (!m_bAllowParentShow)
return; return;
@@ -322,7 +314,7 @@ void StatusIndicatorFactory::implts_makeParentVisibleIfAllowed()
css::uno::Reference< css::awt::XWindow > xPluggWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY); css::uno::Reference< css::awt::XWindow > xPluggWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
css::uno::Reference< css::uno::XComponentContext > xContext( m_xContext); css::uno::Reference< css::uno::XComponentContext > xContext( m_xContext);
aReadLock.unlock(); aReadLock.clear();
// <- SAFE ---------------------------------- // <- SAFE ----------------------------------
css::uno::Reference< css::awt::XWindow > xParentWindow; css::uno::Reference< css::awt::XWindow > xParentWindow;
@@ -406,12 +398,12 @@ void StatusIndicatorFactory::implts_makeParentVisibleIfAllowed()
void StatusIndicatorFactory::impl_createProgress() void StatusIndicatorFactory::impl_createProgress()
{ {
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
Guard aReadLock(m_aLock); osl::ClearableMutexGuard aReadLock(m_mutex);
css::uno::Reference< css::frame::XFrame > xFrame (m_xFrame.get() , css::uno::UNO_QUERY); css::uno::Reference< css::frame::XFrame > xFrame (m_xFrame.get() , css::uno::UNO_QUERY);
css::uno::Reference< css::awt::XWindow > xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY); css::uno::Reference< css::awt::XWindow > xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
aReadLock.lock(); aReadLock.clear();
// <- SAFE ---------------------------------- // <- SAFE ----------------------------------
css::uno::Reference< css::task::XStatusIndicator > xProgress; css::uno::Reference< css::task::XStatusIndicator > xProgress;
@@ -445,23 +437,20 @@ void StatusIndicatorFactory::impl_createProgress()
} }
} }
// SAFE -> ---------------------------------- osl::MutexGuard g(m_mutex);
Guard aWriteLock(m_aLock);
m_xProgress = xProgress; m_xProgress = xProgress;
aWriteLock.lock();
// <- SAFE ----------------------------------
} }
void StatusIndicatorFactory::impl_showProgress() void StatusIndicatorFactory::impl_showProgress()
{ {
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
Guard aReadLock(m_aLock); osl::ClearableMutexGuard aReadLock(m_mutex);
css::uno::Reference< css::frame::XFrame > xFrame (m_xFrame.get() , css::uno::UNO_QUERY); css::uno::Reference< css::frame::XFrame > xFrame (m_xFrame.get() , css::uno::UNO_QUERY);
css::uno::Reference< css::awt::XWindow > xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY); css::uno::Reference< css::awt::XWindow > xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
aReadLock.lock(); aReadLock.clear();
// <- SAFE ---------------------------------- // <- SAFE ----------------------------------
css::uno::Reference< css::task::XStatusIndicator > xProgress; css::uno::Reference< css::task::XStatusIndicator > xProgress;
@@ -489,11 +478,8 @@ void StatusIndicatorFactory::impl_showProgress()
} }
} }
// SAFE -> ---------------------------------- osl::MutexGuard g(m_mutex);
Guard aWriteLock(m_aLock);
m_xProgress = xProgress; m_xProgress = xProgress;
aWriteLock.lock();
// <- SAFE ----------------------------------
} }
} }
@@ -501,12 +487,12 @@ void StatusIndicatorFactory::impl_showProgress()
void StatusIndicatorFactory::impl_hideProgress() void StatusIndicatorFactory::impl_hideProgress()
{ {
// SAFE -> ---------------------------------- // SAFE -> ----------------------------------
Guard aReadLock(m_aLock); osl::ClearableMutexGuard aReadLock(m_mutex);
css::uno::Reference< css::frame::XFrame > xFrame (m_xFrame.get() , css::uno::UNO_QUERY); css::uno::Reference< css::frame::XFrame > xFrame (m_xFrame.get() , css::uno::UNO_QUERY);
css::uno::Reference< css::awt::XWindow > xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY); css::uno::Reference< css::awt::XWindow > xWindow(m_xPluggWindow.get(), css::uno::UNO_QUERY);
aReadLock.lock(); aReadLock.clear();
// <- SAFE ---------------------------------- // <- SAFE ----------------------------------
if (xFrame.is()) if (xFrame.is())
@@ -527,21 +513,18 @@ void StatusIndicatorFactory::impl_hideProgress()
void StatusIndicatorFactory::impl_reschedule(sal_Bool bForce) void StatusIndicatorFactory::impl_reschedule(sal_Bool bForce)
{ {
// SAFE -> // SAFE ->
Guard aReadLock(m_aLock); osl::ClearableMutexGuard aReadLock(m_mutex);
if (m_bDisableReschedule) if (m_bDisableReschedule)
return; return;
aReadLock.unlock(); aReadLock.clear();
// <- SAFE // <- SAFE
sal_Bool bReschedule = bForce; sal_Bool bReschedule = bForce;
if (!bReschedule) if (!bReschedule)
{ {
// SAFE -> osl::MutexGuard g(m_mutex);
Guard aWriteLock(m_aLock);
bReschedule = m_bAllowReschedule; bReschedule = m_bAllowReschedule;
m_bAllowReschedule = sal_False; m_bAllowReschedule = sal_False;
aWriteLock.unlock();
// <- SAFE
} }
if (!bReschedule) if (!bReschedule)
@@ -570,8 +553,7 @@ void StatusIndicatorFactory::impl_reschedule(sal_Bool bForce)
void StatusIndicatorFactory::impl_startWakeUpThread() void StatusIndicatorFactory::impl_startWakeUpThread()
{ {
// SAFE -> osl::MutexGuard g(m_mutex);
Guard aWriteLock(m_aLock);
if (m_bDisableReschedule) if (m_bDisableReschedule)
return; return;
@@ -581,23 +563,18 @@ void StatusIndicatorFactory::impl_startWakeUpThread()
m_pWakeUp = new WakeUpThread(this); m_pWakeUp = new WakeUpThread(this);
m_pWakeUp->create(); m_pWakeUp->create();
} }
aWriteLock.unlock();
// <- SAFE
} }
void StatusIndicatorFactory::impl_stopWakeUpThread() void StatusIndicatorFactory::impl_stopWakeUpThread()
{ {
// SAFE -> osl::MutexGuard g(m_mutex);
Guard aWriteLock(m_aLock);
if (m_pWakeUp) if (m_pWakeUp)
{ {
// Thread kill itself after terminate()! // Thread kill itself after terminate()!
m_pWakeUp->terminate(); m_pWakeUp->terminate();
m_pWakeUp = 0; m_pWakeUp = 0;
} }
aWriteLock.unlock();
// <- SAFE
} }
} // namespace framework } // namespace framework