mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-18 11:39:00 +02:00
trunk/branch integration: ScopedLockWithUnlock
This commit is contained in:
@@ -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
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user