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)
22class Q_CORE_EXPORT QBasicMutex
24 Q_DISABLE_COPY_MOVE(QBasicMutex)
26 static constexpr bool FutexAlwaysAvailable =
27#if defined(Q_OS_FREEBSD) || defined(Q_OS_LINUX) || defined(Q_OS_WIN)
35 constexpr QBasicMutex()
40 inline void lock()
noexcept(FutexAlwaysAvailable) {
41 QtTsan::mutexPreLock(
this, 0u);
46 QtTsan::mutexPostLock(
this, 0u, 0);
50 inline void unlock()
noexcept {
51 Q_ASSERT(d_ptr.loadRelaxed());
53 QtTsan::mutexPreUnlock(
this, 0u);
55 if constexpr (FutexAlwaysAvailable) {
57 if (QMutexPrivate *d = d_ptr.fetchAndStoreRelease(
nullptr); d != dummyLocked())
58 unlockInternalFutex(d);
61 if (QMutexPrivate *d; !d_ptr.testAndSetRelease(dummyLocked(),
nullptr, d))
65 QtTsan::mutexPostUnlock(
this, 0u);
68 bool tryLock()
noexcept {
69 unsigned tsanFlags = QtTsan::TryLock;
70 QtTsan::mutexPreLock(
this, tsanFlags);
72 const bool success = fastTryLock();
75 tsanFlags |= QtTsan::TryLockFailed;
76 QtTsan::mutexPostLock(
this, tsanFlags, 0);
82 bool try_lock()
noexcept {
return tryLock(); }
85 inline bool fastTryLock()
noexcept
87 if (d_ptr.loadRelaxed() !=
nullptr)
89 return d_ptr.testAndSetAcquire(
nullptr, dummyLocked());
92 void lockInternal()
noexcept(FutexAlwaysAvailable);
93 bool lockInternal(QDeadlineTimer timeout)
noexcept(FutexAlwaysAvailable);
94#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
95 bool lockInternal(
int timeout)
noexcept(FutexAlwaysAvailable);
96 void unlockInternal()
noexcept;
98 void unlockInternalFutex(
void *d)
noexcept;
99 void unlockInternal(
void *d)
noexcept;
100#if QT_CORE_REMOVED_SINCE(6
, 9
)
101 void destroyInternal(QMutexPrivate *d);
103 void destroyInternal(
void *d);
105 QBasicAtomicPointer<QMutexPrivate> d_ptr;
106 static inline QMutexPrivate *dummyLocked() {
107 return reinterpret_cast<QMutexPrivate *>(quintptr(1));
111 friend class QMutexPrivate;
114class Q_CORE_EXPORT QMutex :
public QBasicMutex
117 constexpr QMutex() =
default;
120 QMutexPrivate *d = d_ptr.loadRelaxed();
126 inline void lock()
noexcept(FutexAlwaysAvailable);
127 inline void unlock()
noexcept;
128 bool tryLock()
noexcept;
132 bool try_lock()
noexcept {
return tryLock(); }
135 using QBasicMutex::tryLock;
136 bool tryLock(
int timeout)
noexcept(FutexAlwaysAvailable)
138 return tryLock(QDeadlineTimer(timeout));
141 bool tryLock(QDeadlineTimer timeout)
noexcept(FutexAlwaysAvailable)
143 unsigned tsanFlags = QtTsan::TryLock;
144 QtTsan::mutexPreLock(
this, tsanFlags);
146 bool success = fastTryLock();
149 QtTsan::mutexPostLock(
this, tsanFlags, 0);
153 success = lockInternal(timeout);
156 tsanFlags |= QtTsan::TryLockFailed;
157 QtTsan::mutexPostLock(
this, tsanFlags, 0);
163 template <
class Rep,
class Period>
164 bool try_lock_for(std::chrono::duration<Rep, Period> duration)
166 return tryLock(QDeadlineTimer(duration));
170 template<
class Clock,
class Duration>
171 bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
173 return tryLock(QDeadlineTimer(timePoint));
177class Q_CORE_EXPORT QRecursiveMutex
179 Q_DISABLE_COPY_MOVE(QRecursiveMutex)
182 QAtomicPointer<
void> owner =
nullptr;
186 static constexpr bool LockIsNoexcept =
noexcept(std::declval<QMutex>().lock());
189 constexpr QRecursiveMutex() =
default;
194 void lock()
noexcept(LockIsNoexcept)
195 { tryLock(QDeadlineTimer(QDeadlineTimer::Forever)); }
196 QT_CORE_INLINE_SINCE(6, 6)
197 bool tryLock(
int timeout)
noexcept(LockIsNoexcept);
198 bool tryLock(QDeadlineTimer timer = {})
noexcept(LockIsNoexcept);
200 void unlock()
noexcept;
203 bool try_lock()
noexcept(LockIsNoexcept) {
return tryLock(); }
206 template <
class Rep,
class Period>
207 bool try_lock_for(std::chrono::duration<Rep, Period> duration)
209 return tryLock(QDeadlineTimer(duration));
213 template<
class Clock,
class Duration>
214 bool try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
216 return tryLock(QDeadlineTimer(timePoint));
220#if QT_CORE_INLINE_IMPL_SINCE(6
, 6
)
221bool QRecursiveMutex::tryLock(
int timeout)
noexcept(LockIsNoexcept)
223 return tryLock(QDeadlineTimer(timeout));
227template <
typename Mutex>
232 static constexpr bool LockIsNoexcept =
false;
234 static constexpr bool LockIsNoexcept =
noexcept(std::declval<Mutex>().lock());
238 inline explicit QMutexLocker(Mutex *mutex)
noexcept(LockIsNoexcept)
241 if (Q_LIKELY(mutex)) {
248 inline QMutexLocker(QMutexLocker &&other)
noexcept
249 : m_mutex(std::exchange(other.m_mutex,
nullptr)),
250 m_isLocked(std::exchange(other.m_isLocked,
false))
253 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMutexLocker)
255 inline ~QMutexLocker()
261 inline bool isLocked()
const noexcept
266 inline void unlock()
noexcept
268 Q_ASSERT(m_isLocked);
273 inline void relock()
noexcept(LockIsNoexcept)
275 Q_ASSERT(!m_isLocked);
280 inline void swap(QMutexLocker &other)
noexcept
282 qt_ptr_swap(m_mutex, other.m_mutex);
283 std::swap(m_isLocked, other.m_isLocked);
291 Q_DISABLE_COPY(QMutexLocker)
294 bool m_isLocked =
false;
303 constexpr QMutex()
noexcept { }
305 inline void lock()
noexcept {}
306 inline bool tryLock(
int timeout = 0)
noexcept { Q_UNUSED(timeout);
return true; }
307 inline bool try_lock()
noexcept {
return true; }
308 inline void unlock()
noexcept {}
310 template <
class Rep,
class Period>
311 inline bool try_lock_for(
std::chrono::duration<Rep, Period> duration)
noexcept
317 template<
class Clock,
class Duration>
318 inline bool try_lock_until(
std::chrono::time_point<Clock, Duration> timePoint)
noexcept
325 Q_DISABLE_COPY(QMutex)
330template <
typename Mutex>
340 inline Mutex *
mutex()
const noexcept {
return nullptr; }
QByteArray & operator*() noexcept
QByteArray::Base64DecodingStatus decodingStatus
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
void swap(QByteArray::FromBase64Result &other) noexcept
operator bool() const noexcept
\variable QByteArray::FromBase64Result::decoded
const QByteArray & operator*() const noexcept
Returns the decoded byte array.
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
\inmodule QtCore\reentrant
int initFrom(const QMessageLogContext &logContext)
void populateBacktrace(int frameCount)
QInternalMessageLogContext(const QMessageLogContext &logContext, const QLoggingCategory &categoryOverride)
std::optional< BacktraceStorage > backtrace
static constexpr int DefaultBacktraceDepth
constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
constexpr QMessageLogContext() noexcept=default
QDebug debug(CategoryFunction catFunc) const
QDebug debug(const QLoggingCategory &cat) const
Logs a debug message into category cat using a QDebug stream.
void void void void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QDebug debug() const
Logs a debug message using a QDebug stream.
QDebug info(const QLoggingCategory &cat) const
Logs an informational message into the category cat using a QDebug stream.
QDebug info() const
Logs an informational message using a QDebug stream.
QNoDebug noDebug(...) const noexcept
QDebug info(CategoryFunction catFunc) const
Mutex * mutex() const noexcept
Returns the mutex on which the QMutexLocker is operating.
void unlock() noexcept
Unlocks this mutex locker.
~QMutexLocker() noexcept
Destroys the QMutexLocker and unlocks the mutex that was locked in the constructor.
void relock() noexcept
Relocks an unlocked mutex locker.
static Q_CONSTINIT thread_local bool msgHandlerGrabbed
static const char ifCriticalTokenC[]
static const char emptyTokenC[]
static Q_NEVER_INLINE void qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, va_list ap)
static void preformattedMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &formattedMessage)
static bool systemHasStderr()
Returns true if writing to stderr is supported.
static const char endifTokenC[]
static bool isDefaultCategory(const char *category)
static const char messageTokenC[]
static constexpr SystemMessageSink systemMessageSink
static void qt_maybe_message_fatal(QtMsgType, const QMessageLogContext &context, String &&message)
\inmodule QtCore \title Qt Logging Types
#define HANDLE_IF_TOKEN(LEVEL)
Q_DECLARE_TYPEINFO(QMessagePattern::BacktraceParams, Q_RELOCATABLE_TYPE)
static const char timeTokenC[]
static bool is_fatal_count_down(QAtomicInt &n)
static const char qthreadptrTokenC[]
static const char fileTokenC[]
static const char ifDebugTokenC[]
static const char ifFatalTokenC[]
static const char categoryTokenC[]
static const char lineTokenC[]
static const char typeTokenC[]
static const char ifCategoryTokenC[]
static int checked_var_value(const char *varname)
static const char pidTokenC[]
Q_TRACE_POINT(qtcore, qt_message_print, int type, const char *category, const char *function, const char *file, int line, const QString &message)
static const char threadidTokenC[]
static QString formatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &str)
static const char backtraceTokenC[]
static const char functionTokenC[]
static const char ifWarningTokenC[]
static const char appnameTokenC[]
static bool isFatal(QtMsgType msgType)
static const char ifInfoTokenC[]
static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message)
static bool stderrHasConsoleAttached()
Returns true if writing to stderr will end up in a console/terminal visible to the user.
Combined button and popup list for selecting options.
QDebug printAssociativeContainer(QDebug debug, const char *which, const AssociativeContainer &c)
bool shouldLogToStderr()
Returns true if logging stderr should be ensured.
QDebug printSequentialContainer(QDebug debug, const char *which, const SequentialContainer &c)
QByteArray operator""_ba(const char *str, size_t size) noexcept
QT_BEGIN_NAMESPACE Q_NORETURN void qAbort()
QByteArray operator+(const QByteArray &a1, const char *a2)
QByteArray qUncompress(const QByteArray &data)
QByteArray operator+(char a1, const QByteArray &a2)
QByteArray operator+(QByteArray &&lhs, char rhs)
QByteArray operator+(const QByteArray &a1, char a2)
QByteArray operator+(const char *a1, const QByteArray &a2)
QByteArray operator+(QByteArray &&lhs, const QByteArray &rhs)
qsizetype erase_if(QByteArray &ba, Predicate pred)
QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
QByteArray qCompress(const QByteArray &data, int compressionLevel=-1)
qsizetype erase(QByteArray &ba, const T &t)
QByteArray operator+(QByteArray &&lhs, const char *rhs)
#define __has_cpp_attribute(x)
void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, Int value)
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, quint64 value)
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, uint value)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
#define QT_MESSAGELOG_FUNC
Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg,...)
Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(const char *msg,...)
#define QT_MESSAGELOG_FILE
#define QT_MESSAGE_LOGGER_NORETURN
#define QT_MESSAGELOG_LINE
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern)
#define QT_MESSAGELOGCONTEXT
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const QString &message)
void(* QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &)
#define Q_LOGGING_CATEGORY(name,...)
#define QT_MESSAGE_LOGGER_COMMON(category, level)
#define Q_DECLARE_LOGGING_CATEGORY(name)
QString backtraceSeparator
void setPattern(const QString &pattern)
std::unique_ptr< std::unique_ptr< const char[]>[]> literals
std::chrono::steady_clock::time_point appStartTime
std::unique_ptr< const char *[]> tokens
QList< QString > timeArgs
static constexpr bool Value
static constexpr bool Value