Tiny mistake in previous commit.

This commit is contained in:
JoelKatz
2011-11-11 16:38:49 -08:00
parent 3452211310
commit 3f8f7789b3

View File

@@ -6,47 +6,46 @@
// This is a returnable lock holder. // This is a returnable lock holder.
// I don't know why Boost doesn't provide a good way to do this. // I don't know why Boost doesn't provide a good way to do this.
class ScopedLock 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)
{ {
mMutex->lock(); private:
} boost::mutex *mMutex; // parent object has greater scope, so guaranteed valid
mutable bool mValid;
~ScopedLock() ScopedLock(); // no implementation
{
if(mValid) mMutex->unlock(); public:
} ScopedLock(boost::mutex &mutex) : mMutex(&mutex), mValid(true)
{
ScopedLock(const ScopedLock &sl) mMutex->lock();
{
mMutex=sl.mMutex;
if(sl.mValid)
{
mValid=true;
sl.mValid=false;
} }
else mValid=false;
}
ScopedLock &operator=(const ScopedLock &sl) ~ScopedLock()
{ // we inherit any lock the other class member had
if(mValid) mMutex->unlock();
mMutex=sl.mMutex;
if(sl.mValid)
{ {
if(mValid) mMutex->unlock(); 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 #endif