summaryrefslogtreecommitdiff
path: root/src/utils/mutex.h
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2011-09-15 04:54:32 +0800
committerYohann Ferreira <yohann.ferreira@orange.fr>2011-09-16 07:10:21 +0800
commitf295cd8484f28d634bc6c0c3c33ea77b811a94fd (patch)
tree4b42c351e6a0f563ae098c3734aaeb5b6391c652 /src/utils/mutex.h
parent8e8fef21ee978fa2ab58b0639a351ba17c66d5d4 (diff)
downloadmana-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.h12
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