Kaydet (Commit) 3a93809d authored tarafından Noel Grandin's avatar Noel Grandin

improvements to ShareableMutex

- add some docs
- remove unnecessary null checks
- improve field name

Change-Id: I8299ec0d56ee5d903f05f2790f97f90ca00663cb
üst 0a906439
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
namespace framework namespace framework
{ {
/**
* This acts like a rtl::Reference<osl::Mutex>
*/
class FWI_DLLPUBLIC ShareableMutex class FWI_DLLPUBLIC ShareableMutex
{ {
public: public:
...@@ -34,12 +37,15 @@ class FWI_DLLPUBLIC ShareableMutex ...@@ -34,12 +37,15 @@ class FWI_DLLPUBLIC ShareableMutex
ShareableMutex( const ShareableMutex& rShareableMutex ); ShareableMutex( const ShareableMutex& rShareableMutex );
const ShareableMutex& operator=( const ShareableMutex& rShareableMutex ); const ShareableMutex& operator=( const ShareableMutex& rShareableMutex );
~ShareableMutex(); ~ShareableMutex() { m_pMutexRef->release(); }
/** acquire the shared mutex */
void acquire(); void acquire();
/** release the shared mutex */
void release(); void release();
private: private:
/* ShareableMutex::MutexRef will destroy itself when the last ShareableMutex pointing to it is destroyed */
struct MutexRef struct MutexRef
{ {
MutexRef() : m_refCount(0) {} MutexRef() : m_refCount(0) {}
...@@ -58,7 +64,7 @@ class FWI_DLLPUBLIC ShareableMutex ...@@ -58,7 +64,7 @@ class FWI_DLLPUBLIC ShareableMutex
osl::Mutex m_oslMutex; osl::Mutex m_oslMutex;
}; };
MutexRef* pMutexRef; MutexRef* m_pMutexRef;
}; };
class ShareGuard class ShareGuard
......
...@@ -24,43 +24,32 @@ namespace framework ...@@ -24,43 +24,32 @@ namespace framework
ShareableMutex::ShareableMutex() ShareableMutex::ShareableMutex()
{ {
pMutexRef = new MutexRef; m_pMutexRef = new MutexRef;
pMutexRef->acquire(); m_pMutexRef->acquire();
} }
ShareableMutex::ShareableMutex( const ShareableMutex& rShareableMutex ) ShareableMutex::ShareableMutex( const ShareableMutex& rShareableMutex )
{ {
pMutexRef = rShareableMutex.pMutexRef; m_pMutexRef = rShareableMutex.m_pMutexRef;
if ( pMutexRef ) m_pMutexRef->acquire();
pMutexRef->acquire();
} }
const ShareableMutex& ShareableMutex::operator=( const ShareableMutex& rShareableMutex ) const ShareableMutex& ShareableMutex::operator=( const ShareableMutex& rShareableMutex )
{ {
if ( rShareableMutex.pMutexRef ) rShareableMutex.m_pMutexRef->acquire();
rShareableMutex.pMutexRef->acquire(); m_pMutexRef->release();
if ( pMutexRef ) m_pMutexRef = rShareableMutex.m_pMutexRef;
pMutexRef->release();
pMutexRef = rShareableMutex.pMutexRef;
return *this; return *this;
} }
ShareableMutex::~ShareableMutex()
{
if ( pMutexRef )
pMutexRef->release();
}
void ShareableMutex::acquire() void ShareableMutex::acquire()
{ {
if ( pMutexRef ) m_pMutexRef->m_oslMutex.acquire();
pMutexRef->m_oslMutex.acquire();
} }
void ShareableMutex::release() void ShareableMutex::release()
{ {
if ( pMutexRef ) m_pMutexRef->m_oslMutex.release();
pMutexRef->m_oslMutex.release();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment