7#include <QtCore/qglobal.h>
8#include <QtCore/qatomic.h>
9#include <QtCore/qdeadlinetimer.h>
10#include <QtCore/qtsan_impl.h>
14#if QT_CONFIG(thread) || defined(Q_QDOC)
16#if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
17# define QT_MUTEX_LOCK_NOEXCEPT noexcept
19# define QT_MUTEX_LOCK_NOEXCEPT
35 inline void lock() QT_MUTEX_LOCK_NOEXCEPT {
45 inline void unlock() noexcept {
60 const bool success = fastTryLock();
70 bool try_lock() noexcept {
return tryLock(); }
73 inline bool fastTryLock() noexcept
75 if (d_ptr.loadRelaxed() !=
nullptr)
77 return d_ptr.testAndSetAcquire(
nullptr, dummyLocked());
79 inline bool fastTryUnlock() noexcept {
80 return d_ptr.testAndSetRelease(dummyLocked(),
nullptr);
83 void lockInternal() QT_MUTEX_LOCK_NOEXCEPT;
85#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
86 bool lockInternal(
int timeout) QT_MUTEX_LOCK_NOEXCEPT;
88 void unlockInternal() noexcept;
103 constexpr QMutex() =
default;
112 inline void lock() QT_MUTEX_LOCK_NOEXCEPT;
113 inline
void unlock() noexcept;
118 bool try_lock() noexcept {
return tryLock(); }
132 bool success = fastTryLock();
139 success = lockInternal(
timeout);
149 template <
class Rep,
class Period>
150 bool try_lock_for(std::chrono::duration<Rep, Period> duration)
156 template<
class Clock,
class Duration>
157 bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
179 void lock() QT_MUTEX_LOCK_NOEXCEPT
181 QT_CORE_INLINE_SINCE(6, 6)
188 bool try_lock() QT_MUTEX_LOCK_NOEXCEPT {
return tryLock(); }
191 template <
class Rep,
class Period>
192 bool try_lock_for(std::chrono::duration<Rep, Period> duration)
198 template<
class Clock,
class Duration>
199 bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
207 {
lock();
return true; }
211#if QT_CORE_INLINE_IMPL_SINCE(6, 6)
218template <
typename Mutex>
234 : m_mutex(std::exchange(
other.m_mutex,
nullptr)),
235 m_isLocked(std::exchange(
other.m_isLocked,
false))
238 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(
QMutexLocker)
246 inline bool isLocked() const noexcept
251 inline void unlock() noexcept
258 inline void relock() QT_MUTEX_LOCK_NOEXCEPT
268 std::swap(m_isLocked,
other.m_isLocked);
279 bool m_isLocked =
false;
295 template <
class Rep,
class Period>
296 inline bool try_lock_for(std::chrono::duration<Rep, Period> duration)
noexcept
302 template<
class Clock,
class Duration>
303 inline bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
noexcept
315template <
typename Mutex>
325 inline Mutex *
mutex() const noexcept {
return nullptr; }
\macro Q_ATOMIC_INTnn_IS_SUPPORTED
ForeverConstant
\value Forever Used when creating a QDeadlineTimer to indicate the deadline should not expire
static constexpr ForeverConstant Forever
void unlock() noexcept
Unlocks this mutex locker.
Q_NODISCARD_CTOR QMutexLocker(Mutex *) noexcept
Constructs a QMutexLocker and locks mutex.
~QMutexLocker() noexcept
Destroys the QMutexLocker and unlocks the mutex that was locked in the constructor.
void relock() noexcept
Relocks an unlocked mutex locker.
Mutex * mutex() const noexcept
Returns the mutex on which the QMutexLocker is operating.
bool tryLock(int timeout=0) noexcept
Attempts to lock the mutex.
bool try_lock_for(std::chrono::duration< Rep, Period > duration) noexcept
void unlock() noexcept
Unlocks the mutex.
constexpr QMutex() noexcept
Constructs a new mutex.
bool try_lock_until(std::chrono::time_point< Clock, Duration > timePoint) noexcept
void lock() noexcept
Locks the mutex.
Combined button and popup list for selecting options.
void mutexPostUnlock(void *, unsigned)
void mutexPreUnlock(void *, unsigned)
void mutexPreLock(void *, unsigned)
void mutexPostLock(void *, unsigned, int)
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
mutex tryLock(deadline.remainingTime())
[4]