43 #include <QtCore/qglobal.h>
44 #include <QtCore/qatomic.h>
47 #if __has_include(<chrono>)
57 #if QT_CONFIG(thread) || defined(Q_CLANG_QDOC)
60 # define QT_MUTEX_LOCK_NOEXCEPT noexcept
62 # define QT_MUTEX_LOCK_NOEXCEPT
69 #if __has_include(<chrono>)
72 template<
class Rep,
class Period>
73 static int convertToMilliseconds(std::chrono::duration<Rep, Period> duration)
80 if (duration <= duration.zero())
85 std::chrono::milliseconds wait = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
87 wait += std::chrono::milliseconds(1);
89 const auto ms = wait.count();
90 const auto maxInt = (std::numeric_limits<int>::max)();
92 return ms < maxInt ? int(
ms) : maxInt;
106 inline void lock() QT_MUTEX_LOCK_NOEXCEPT {
112 inline void unlock() noexcept {
114 if (!fastTryUnlock())
119 return fastTryLock();
123 bool try_lock() noexcept {
return tryLock(); }
126 inline bool fastTryLock() noexcept {
127 return d_ptr.testAndSetAcquire(
nullptr, dummyLocked());
129 inline bool fastTryUnlock() noexcept {
130 return d_ptr.testAndSetRelease(dummyLocked(),
nullptr);
133 void lockInternal() QT_MUTEX_LOCK_NOEXCEPT;
134 bool lockInternal(
int timeout) QT_MUTEX_LOCK_NOEXCEPT;
135 void unlockInternal() noexcept;
150 constexpr
QMutex() =
default;
159 inline void lock() QT_MUTEX_LOCK_NOEXCEPT;
165 bool try_lock() noexcept {
return tryLock(); }
177 template <
class Rep,
class Period>
178 bool try_lock_for(std::chrono::duration<Rep, Period> duration)
180 return tryLock(QtPrivate::convertToMilliseconds(duration));
184 template<
class Clock,
class Duration>
185 bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
190 return try_lock_for(timePoint -
Clock::now());
210 void lock() QT_MUTEX_LOCK_NOEXCEPT
217 bool try_lock() QT_MUTEX_LOCK_NOEXCEPT {
return tryLock(); }
220 template <
class Rep,
class Period>
221 bool try_lock_for(std::chrono::duration<Rep, Period> duration)
223 return tryLock(QtPrivate::convertToMilliseconds(duration));
227 template<
class Clock,
class Duration>
228 bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
233 return try_lock_for(timePoint -
Clock::now());
237 template <
typename Mutex>
253 inline void unlock() noexcept
261 inline void relock() QT_MUTEX_LOCK_NOEXCEPT
279 bool 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
315 template <
typename Mutex>
The QMutex class provides access serialization between threads.
bool tryLock(int timeout=0) noexcept
bool try_lock_for(std::chrono::duration< Rep, Period > duration) noexcept
constexpr QMutex() noexcept
bool try_lock_until(std::chrono::time_point< Clock, Duration > timePoint) noexcept
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes.
QMutexLocker(Mutex *) noexcept
Mutex * mutex() const noexcept
The QRecursiveMutex class provides access serialization between threads.
auto it unsigned count const
std::chrono::milliseconds ms
#define Q_DISABLE_COPY_MOVE(Class)
#define Q_DISABLE_COPY(Class)
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
mutex tryLock(deadline.remainingTime())
[4]