improvements to ShareableMutex
- add some docs - remove unnecessary null checks - improve field name Change-Id: I8299ec0d56ee5d903f05f2790f97f90ca00663cb
This commit is contained in:
@@ -27,6 +27,9 @@
|
||||
namespace framework
|
||||
{
|
||||
|
||||
/**
|
||||
* This acts like a rtl::Reference<osl::Mutex>
|
||||
*/
|
||||
class FWI_DLLPUBLIC ShareableMutex
|
||||
{
|
||||
public:
|
||||
@@ -34,12 +37,15 @@ class FWI_DLLPUBLIC ShareableMutex
|
||||
ShareableMutex( const ShareableMutex& rShareableMutex );
|
||||
const ShareableMutex& operator=( const ShareableMutex& rShareableMutex );
|
||||
|
||||
~ShareableMutex();
|
||||
~ShareableMutex() { m_pMutexRef->release(); }
|
||||
|
||||
/** acquire the shared mutex */
|
||||
void acquire();
|
||||
/** release the shared mutex */
|
||||
void release();
|
||||
|
||||
private:
|
||||
/* ShareableMutex::MutexRef will destroy itself when the last ShareableMutex pointing to it is destroyed */
|
||||
struct MutexRef
|
||||
{
|
||||
MutexRef() : m_refCount(0) {}
|
||||
@@ -58,7 +64,7 @@ class FWI_DLLPUBLIC ShareableMutex
|
||||
osl::Mutex m_oslMutex;
|
||||
};
|
||||
|
||||
MutexRef* pMutexRef;
|
||||
MutexRef* m_pMutexRef;
|
||||
};
|
||||
|
||||
class ShareGuard
|
||||
|
||||
@@ -24,43 +24,32 @@ namespace framework
|
||||
|
||||
ShareableMutex::ShareableMutex()
|
||||
{
|
||||
pMutexRef = new MutexRef;
|
||||
pMutexRef->acquire();
|
||||
m_pMutexRef = new MutexRef;
|
||||
m_pMutexRef->acquire();
|
||||
}
|
||||
|
||||
ShareableMutex::ShareableMutex( const ShareableMutex& rShareableMutex )
|
||||
{
|
||||
pMutexRef = rShareableMutex.pMutexRef;
|
||||
if ( pMutexRef )
|
||||
pMutexRef->acquire();
|
||||
m_pMutexRef = rShareableMutex.m_pMutexRef;
|
||||
m_pMutexRef->acquire();
|
||||
}
|
||||
|
||||
const ShareableMutex& ShareableMutex::operator=( const ShareableMutex& rShareableMutex )
|
||||
{
|
||||
if ( rShareableMutex.pMutexRef )
|
||||
rShareableMutex.pMutexRef->acquire();
|
||||
if ( pMutexRef )
|
||||
pMutexRef->release();
|
||||
pMutexRef = rShareableMutex.pMutexRef;
|
||||
rShareableMutex.m_pMutexRef->acquire();
|
||||
m_pMutexRef->release();
|
||||
m_pMutexRef = rShareableMutex.m_pMutexRef;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ShareableMutex::~ShareableMutex()
|
||||
{
|
||||
if ( pMutexRef )
|
||||
pMutexRef->release();
|
||||
}
|
||||
|
||||
void ShareableMutex::acquire()
|
||||
{
|
||||
if ( pMutexRef )
|
||||
pMutexRef->m_oslMutex.acquire();
|
||||
m_pMutexRef->m_oslMutex.acquire();
|
||||
}
|
||||
|
||||
void ShareableMutex::release()
|
||||
{
|
||||
if ( pMutexRef )
|
||||
pMutexRef->m_oslMutex.release();
|
||||
m_pMutexRef->m_oslMutex.release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user