summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2010-10-14 17:40:58 -0500
committerNorbert Thiebaud <nthiebaud@gmail.com>2010-10-25 19:55:37 -0500
commit3d99638e462ece3f2d82ccc7fe4a8d281e3f4068 (patch)
tree70fbf25edcad728a29c649768f0e30c0e10df944
parent7223ecb528c9883bae835ae5b47f7306efa2e256 (diff)
Add a new class SolarMutexClearbleGuard
Few place in the code use vos::OClearbleGuard aGuard(Application::GetSolarMutex()); or something similar. This new class hide this ugliness into SolarMutexClearableGuard aGuard; This also has the merit to push down the vos:: dependency down into one location for this kind of access, which will simplify the vos dependency removal.
-rw-r--r--vcl/inc/vcl/svapp.hxx38
1 files changed, 38 insertions, 0 deletions
diff --git a/vcl/inc/vcl/svapp.hxx b/vcl/inc/vcl/svapp.hxx
index 5a9a27b65278..55c424d050c2 100644
--- a/vcl/inc/vcl/svapp.hxx
+++ b/vcl/inc/vcl/svapp.hxx
@@ -523,6 +523,44 @@ class VCL_DLLPUBLIC SolarMutexGuard
}
};
+class VCL_DLLPUBLIC SolarMutexClearableGuard
+{
+ SolarMutexClearableGuard( const SolarMutexClearableGuard& );
+ const SolarMutexClearableGuard& operator = ( const SolarMutexClearableGuard& );
+ bool m_bCleared;
+public:
+ /** Acquires mutex
+ @param pMutex pointer to mutex which is to be acquired */
+ SolarMutexClearableGuard()
+ : m_bCleared(false)
+ , m_solarMutex( Application::GetSolarMutex() )
+ {
+ m_solarMutex.acquire();
+ }
+
+ /** Releases mutex. */
+ virtual ~SolarMutexClearableGuard()
+ {
+ if( !m_bCleared )
+ {
+ m_solarMutex.release();
+ }
+ }
+
+ /** Releases mutex. */
+ void SAL_CALL clear()
+ {
+ if( !m_bCleared )
+ {
+ m_solarMutex.release();
+ m_bCleared = true;
+ }
+ }
+protected:
+ vos::IMutex& m_solarMutex;
+};
+
+
/**
A helper class that calls Application::ReleaseSolarMutex() in its constructor
and restores the mutex in its destructor.