diff --git a/Foundation/include/Poco/ScopedLock.h b/Foundation/include/Poco/ScopedLock.h index 0da4aa77d..54ee3d66a 100644 --- a/Foundation/include/Poco/ScopedLock.h +++ b/Foundation/include/Poco/ScopedLock.h @@ -72,6 +72,44 @@ private: }; +template +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