summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qmutex.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-03-06 13:34:15 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-03-17 18:57:47 +0100
commit20d0ff1a39c5f9c843f34b6dc1989df526a7367e (patch)
tree62aecde6176a9f82c98a28b4701e41f7a821aef0 /src/corelib/thread/qmutex.h
parent4b8c20a29715a83aeabc5bc325e0e05e33c859f7 (diff)
QMutexLocker: add move semantics
The class is similar to unique_lock in that it allows for unlocking and relocking. Since the locked state is tracked by QMutexLocker itself, it's trivial to make it movable. [ChangeLog][QtCore][QMutexLocker] The class is now movable. Change-Id: I534044f8024575e996c12efb2236761d493798a3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/thread/qmutex.h')
-rw-r--r--src/corelib/thread/qmutex.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index f57a95de223..e10a3f8f3db 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -247,6 +247,13 @@ public:
}
}
+ inline QMutexLocker(QMutexLocker &&other) noexcept
+ : m_mutex(std::exchange(other.m_mutex, nullptr)),
+ m_isLocked(std::exchange(other.m_isLocked, false))
+ {}
+
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMutexLocker)
+
inline ~QMutexLocker()
{
unlock();
@@ -275,6 +282,12 @@ public:
}
}
+ inline void swap(QMutexLocker &other) noexcept
+ {
+ qt_ptr_swap(m_mutex, other.m_mutex);
+ std::swap(m_isLocked, other.m_isLocked);
+ }
+
Mutex *mutex() const
{
return m_mutex;