diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2011-09-15 04:54:32 +0800 |
---|---|---|
committer | Yohann Ferreira <yohann.ferreira@orange.fr> | 2011-09-16 07:10:21 +0800 |
commit | f295cd8484f28d634bc6c0c3c33ea77b811a94fd (patch) | |
tree | 4b42c351e6a0f563ae098c3734aaeb5b6391c652 /src/utils/mutex.h | |
parent | 8e8fef21ee978fa2ab58b0639a351ba17c66d5d4 (diff) | |
download | mana-f295cd8484f28d634bc6c0c3c33ea77b811a94fd.tar.gz mana-f295cd8484f28d634bc6c0c3c33ea77b811a94fd.tar.bz2 mana-f295cd8484f28d634bc6c0c3c33ea77b811a94fd.tar.xz mana-f295cd8484f28d634bc6c0c3c33ea77b811a94fd.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/mutex.h')
-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 |