#ifndef __SCOPEDLOCKHOLDER__ #define __SCOPEDLOCKHOLDER__ #include #include #include #include #include // A lock holder that can be returned and copied by value // When the last reference goes away, the lock is released class ScopedLock { protected: mutable boost::shared_ptr > mHolder; public: ScopedLock(boost::recursive_mutex& mutex) : mHolder(boost::make_shared >(boost::ref(mutex))) { ; } void lock() const { mHolder->lock(); } void unlock() const { mHolder->unlock(); } }; #endif