From 3f8f7789b3fd4dc0ae6078786c555373c78bcbd5 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 11 Nov 2011 16:38:49 -0800 Subject: [PATCH] Tiny mistake in previous commit. --- ScopedLock.h | 69 ++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/ScopedLock.h b/ScopedLock.h index 2d9e96e60f..fa3b142c2e 100644 --- a/ScopedLock.h +++ b/ScopedLock.h @@ -6,47 +6,46 @@ // This is a returnable lock holder. // I don't know why Boost doesn't provide a good way to do this. -class ScopedLock -{ -private: - boost::mutex *mMutex; // parent object has greater scope, so guaranteed valid - mutable bool mValid; - - ScopedLock(); // no implementation - -public: - ScopedLock(boost::mutex &mutex) : mMutex(&mutex), mValid(true) + class ScopedLock { - mMutex->lock(); - } + private: + boost::mutex *mMutex; // parent object has greater scope, so guaranteed valid + mutable bool mValid; - ~ScopedLock() - { - if(mValid) mMutex->unlock(); - } - - ScopedLock(const ScopedLock &sl) - { - mMutex=sl.mMutex; - if(sl.mValid) - { - mValid=true; - sl.mValid=false; + ScopedLock(); // no implementation + + public: + ScopedLock(boost::mutex &mutex) : mMutex(&mutex), mValid(true) + { + mMutex->lock(); } - else mValid=false; - } - ScopedLock &operator=(const ScopedLock &sl) - { // we inherit any lock the other class member had - if(mValid) mMutex->unlock(); - mMutex=sl.mMutex; - if(sl.mValid) + ~ScopedLock() { if(mValid) mMutex->unlock(); - mValid=true; - sl.mValid=false; } - } -}; + + ScopedLock(const ScopedLock &sl) + { + mMutex=sl.mMutex; + if(sl.mValid) + { + mValid=true; + sl.mValid=false; + } + else mValid=false; + } + + ScopedLock &operator=(const ScopedLock &sl) + { // we inherit any lock the other class member had + if(mValid) mMutex->unlock(); + mMutex=sl.mMutex; + if(sl.mValid) + { + mValid=true; + sl.mValid=false; + } + } + }; #endif