Author: wyoung
Date: Thu Dec 27 03:02:30 2007
New Revision: 2027
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2027&view=rev
Log:
Added ScopedLock class, a wrapper around BeecryptMutex to add
scope-bound locking and unlocking. Created by Jonathan Wakely for use
in an upcoming patch.
Modified:
trunk/lib/beemutex.h
Modified: trunk/lib/beemutex.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/beemutex.h?rev=2027&r1=2026&r2=2027&view=diff
==============================================================================
--- trunk/lib/beemutex.h (original)
+++ trunk/lib/beemutex.h Thu Dec 27 03:02:30 2007
@@ -83,6 +83,35 @@
void* pmutex_;
};
+
+/// \brief Wrapper around BeecryptMutex to add scope-bound locking
+/// and unlocking.
+///
+/// This allows code to lock a mutex and ensure it will unlock on exit
+/// from the enclosing scope even in the face of exceptions. This is
+/// separate from BeecryptMutex because we don't want to make this
+/// behavior mandatory.
+
+class ScopedLock
+{
+public:
+ /// \brief Lock the mutex.
+ explicit ScopedLock(BeecryptMutex& mutex) :
+ mutex_(mutex)
+ {
+ mutex.lock();
+ }
+
+ /// \brief Unlock the mutex.
+ ~ScopedLock() { mutex_.unlock(); }
+
+private:
+ ScopedLock(const ScopedLock&); // can't copy
+ ScopedLock& operator =(const ScopedLock&); // can't assign
+
+ BeecryptMutex& mutex_; ///< the mutex object we manage
+};
+
} // end namespace mysqlpp
#endif // !defined(MYSQLPP_BEEMUTEX_H)
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits