From 74594b897097b6dc61b7525b4389e15be5771dad Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 14 Sep 2011 13:54:32 -0700 Subject: Prevent copying of MutexLocker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a bug here, which wouldn't surface if the copy was elided. Fixed by using a move constructor. Reviewed-by: Thorbjørn Lindeijer --- src/utils/mutex.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/utils/mutex.h b/src/utils/mutex.h index f98bcdfe..92bbd614 100644 --- a/src/utils/mutex.h +++ b/src/utils/mutex.h @@ -53,9 +53,13 @@ class MutexLocker { public: MutexLocker(Mutex *mutex); + MutexLocker(MutexLocker&&); ~MutexLocker(); private: + MutexLocker(const MutexLocker&); // prevent copying + MutexLocker& operator=(const MutexLocker&); + Mutex *mMutex; }; @@ -89,9 +93,15 @@ inline MutexLocker::MutexLocker(Mutex *mutex): mMutex->lock(); } +inline MutexLocker::MutexLocker(MutexLocker&& rhs): + mMutex(rhs.mMutex) +{ + rhs.mMutex = NULL; +} inline MutexLocker::~MutexLocker() { - mMutex->unlock(); + if (mMutex) + mMutex->unlock(); } #endif // MUTEX_H -- cgit v1.2.3-70-g09d2