diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2011-09-14 13:54:32 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2011-09-15 14:32:26 -0700 |
commit | 74594b897097b6dc61b7525b4389e15be5771dad (patch) | |
tree | 1cf631b1014e7a6cc8be5ce379c9f2120aaaa16b /src/utils | |
parent | 0d6c98b33612b548b400e2bd396933936327f6de (diff) | |
download | mana-74594b897097b6dc61b7525b4389e15be5771dad.tar.gz mana-74594b897097b6dc61b7525b4389e15be5771dad.tar.bz2 mana-74594b897097b6dc61b7525b4389e15be5771dad.tar.xz mana-74594b897097b6dc61b7525b4389e15be5771dad.zip |
Prevent copying of MutexLocker
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 <thorbjorn@lindeijer.nl>
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/mutex.h | 12 |
1 files changed, 11 insertions, 1 deletions
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 |