7#include <QtCore/qglobal.h>
8#include <QtCore/qatomic.h>
9#include <QtCore/qdeadlinetimer.h>
10#include <QtCore/qtsan_impl.h>
16#if QT_CONFIG(thread) || defined(Q_QDOC)
18#if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
19# define QT_MUTEX_LOCK_NOEXCEPT noexcept
21# define QT_MUTEX_LOCK_NOEXCEPT
37 inline void lock() QT_MUTEX_LOCK_NOEXCEPT {
47 inline void unlock() noexcept {
62 const bool success = fastTryLock();
72 bool try_lock() noexcept {
return tryLock(); }
75 inline bool fastTryLock() noexcept
77 if (d_ptr.loadRelaxed() !=
nullptr)
79 return d_ptr.testAndSetAcquire(
nullptr, dummyLocked());
81 inline bool fastTryUnlock() noexcept {
82 return d_ptr.testAndSetRelease(dummyLocked(),
nullptr);
85 void lockInternal() QT_MUTEX_LOCK_NOEXCEPT;
87#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
88 bool lockInternal(
int timeout) QT_MUTEX_LOCK_NOEXCEPT;
90 void unlockInternal() noexcept;
105 constexpr QMutex() =
default;
114 inline void lock() QT_MUTEX_LOCK_NOEXCEPT;
115 inline
void unlock() noexcept;
120 bool try_lock() noexcept {
return tryLock(); }
134 bool success = fastTryLock();
141 success = lockInternal(
timeout);
151 template <
class Rep,
class Period>
152 bool try_lock_for(std::chrono::duration<Rep, Period> duration)
158 template<
class Clock,
class Duration>
159 bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
170 QAtomicPointer<void> owner =
nullptr;
181 void lock() QT_MUTEX_LOCK_NOEXCEPT
183 QT_CORE_INLINE_SINCE(6, 6)
190 bool try_lock() QT_MUTEX_LOCK_NOEXCEPT {
return tryLock(); }
193 template <
class Rep,
class Period>
194 bool try_lock_for(std::chrono::duration<Rep, Period> duration)
200 template<
class Clock,
class Duration>
201 bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
207#if QT_CORE_INLINE_IMPL_SINCE(6, 6)
214template <
typename Mutex>
230 : m_mutex(std::exchange(
other.m_mutex,
nullptr)),
231 m_isLocked(std::exchange(
other.m_isLocked,
false))
234 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(
QMutexLocker)
242 inline bool isLocked() const noexcept
247 inline void unlock() noexcept
254 inline void relock() QT_MUTEX_LOCK_NOEXCEPT
264 std::swap(m_isLocked,
other.m_isLocked);
275 bool m_isLocked =
false;
291 template <
class Rep,
class Period>
292 inline bool try_lock_for(std::chrono::duration<Rep, Period> duration)
noexcept
298 template<
class Clock,
class Duration>
299 inline bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
noexcept
311template <
typename Mutex>
321 inline Mutex *
mutex() const noexcept {
return nullptr; }
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]