trunk/branch integration: ScopedLockWithUnlock

This commit is contained in:
Marian Krivos
2011-08-22 17:52:08 +00:00
parent 5f83e82485
commit f215fb195a

View File

@@ -72,6 +72,44 @@ private:
};
template <class M>
class ScopedLockWithUnlock
/// A class that simplifies thread synchronization
/// with a mutex.
/// The constructor accepts a Mutex and locks it.
/// The destructor unlocks the mutex.
/// The unlock() member function allows for manual
/// unlocking of the mutex.
{
public:
ScopedLockWithUnlock(M& mutex): _pMutex(&mutex)
{
_pMutex->lock();
}
~ScopedLockWithUnlock()
{
unlock();
}
void unlock()
{
if (_pMutex)
{
_pMutex->unlock();
_pMutex = 0;
}
}
private:
M* _pMutex;
ScopedLockWithUnlock();
ScopedLockWithUnlock(const ScopedLockWithUnlock&);
ScopedLockWithUnlock& operator = (const ScopedLockWithUnlock&);
};
} // namespace Poco