Port from QAtomic::load() to loadRelaxed()

Semi-automated, just needed ~20 manual fixes:

$ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)load\(\)/$1loadRelaxed\(\)/g' -i \{\} +
$ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)store\(/$1storeRelaxed\(/g' -i \{\} +

It can be easily improved (e.g. for store check that there are no commas
after the opening parens). The most common offender is QLibrary::load,
and some code using std::atomic directly.

Change-Id: I07c38a3c8ed32c924ef4999e85c7e45cf48f0f6c
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Giuseppe D'Angelo 2019-06-10 11:08:29 +02:00 committed by Marc Mutz
parent 84e89c1e9e
commit 34fe9232db
182 changed files with 1385 additions and 1385 deletions

View File

@ -206,9 +206,9 @@ public:
bool shouldStartThread() override bool shouldStartThread() override
{ {
if (forIteration) if (forIteration)
return (currentIndex.load() < iterationCount) && !this->shouldThrottleThread(); return (currentIndex.loadRelaxed() < iterationCount) && !this->shouldThrottleThread();
else // whileIteration else // whileIteration
return (iteratorThreads.load() == 0); return (iteratorThreads.loadRelaxed() == 0);
} }
ThreadFunctionResult threadFunction() override ThreadFunctionResult threadFunction() override
@ -230,7 +230,7 @@ public:
const int currentBlockSize = blockSizeManager.blockSize(); const int currentBlockSize = blockSizeManager.blockSize();
if (currentIndex.load() >= iterationCount) if (currentIndex.loadRelaxed() >= iterationCount)
break; break;
// Atomically reserve a block of iterationCount for this thread. // Atomically reserve a block of iterationCount for this thread.
@ -261,7 +261,7 @@ public:
// Report progress if progress reporting enabled. // Report progress if progress reporting enabled.
if (progressReportingEnabled) { if (progressReportingEnabled) {
completed.fetchAndAddAcquire(finalBlockSize); completed.fetchAndAddAcquire(finalBlockSize);
this->setProgressValue(this->completed.load()); this->setProgressValue(this->completed.loadRelaxed());
} }
if (this->shouldThrottleThread()) if (this->shouldThrottleThread())

View File

@ -91,7 +91,7 @@ ThreadEngineBarrier::ThreadEngineBarrier()
void ThreadEngineBarrier::acquire() void ThreadEngineBarrier::acquire()
{ {
forever { forever {
int localCount = count.load(); int localCount = count.loadRelaxed();
if (localCount < 0) { if (localCount < 0) {
if (count.testAndSetOrdered(localCount, localCount -1)) if (count.testAndSetOrdered(localCount, localCount -1))
return; return;
@ -105,7 +105,7 @@ void ThreadEngineBarrier::acquire()
int ThreadEngineBarrier::release() int ThreadEngineBarrier::release()
{ {
forever { forever {
int localCount = count.load(); int localCount = count.loadRelaxed();
if (localCount == -1) { if (localCount == -1) {
if (count.testAndSetOrdered(-1, 0)) { if (count.testAndSetOrdered(-1, 0)) {
semaphore.release(); semaphore.release();
@ -125,7 +125,7 @@ int ThreadEngineBarrier::release()
void ThreadEngineBarrier::wait() void ThreadEngineBarrier::wait()
{ {
forever { forever {
int localCount = count.load(); int localCount = count.loadRelaxed();
if (localCount == 0) if (localCount == 0)
return; return;
@ -139,7 +139,7 @@ void ThreadEngineBarrier::wait()
int ThreadEngineBarrier::currentCount() int ThreadEngineBarrier::currentCount()
{ {
return count.load(); return count.loadRelaxed();
} }
// releases a thread, unless this is the last thread. // releases a thread, unless this is the last thread.
@ -147,7 +147,7 @@ int ThreadEngineBarrier::currentCount()
bool ThreadEngineBarrier::releaseUnlessLast() bool ThreadEngineBarrier::releaseUnlessLast()
{ {
forever { forever {
int localCount = count.load(); int localCount = count.loadRelaxed();
if (qAbs(localCount) == 1) { if (qAbs(localCount) == 1) {
return false; return false;
} else if (localCount < 0) { } else if (localCount < 0) {

View File

@ -283,11 +283,11 @@ void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress)
qSwap(currentValue, ret); qSwap(currentValue, ret);
q->updateCurrentValue(currentValue); q->updateCurrentValue(currentValue);
static QBasicAtomicInt changedSignalIndex = Q_BASIC_ATOMIC_INITIALIZER(0); static QBasicAtomicInt changedSignalIndex = Q_BASIC_ATOMIC_INITIALIZER(0);
if (!changedSignalIndex.load()) { if (!changedSignalIndex.loadRelaxed()) {
//we keep the mask so that we emit valueChanged only when needed (for performance reasons) //we keep the mask so that we emit valueChanged only when needed (for performance reasons)
changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)")); changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)"));
} }
if (isSignalConnected(changedSignalIndex.load()) && currentValue != ret) { if (isSignalConnected(changedSignalIndex.loadRelaxed()) && currentValue != ret) {
//the value has changed //the value has changed
emit q->valueChanged(currentValue); emit q->valueChanged(currentValue);
} }

View File

@ -610,7 +610,7 @@ QSimpleTextCodec::QSimpleTextCodec(int i) : forwardIndex(i), reverseMap(0)
QSimpleTextCodec::~QSimpleTextCodec() QSimpleTextCodec::~QSimpleTextCodec()
{ {
delete reverseMap.load(); delete reverseMap.loadRelaxed();
} }
static QByteArray *buildReverseMap(int forwardIndex) static QByteArray *buildReverseMap(int forwardIndex)
@ -662,12 +662,12 @@ QByteArray QSimpleTextCodec::convertFromUnicode(const QChar *in, int length, Con
const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?'; const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
int invalid = 0; int invalid = 0;
QByteArray *rmap = reverseMap.load(); QByteArray *rmap = reverseMap.loadRelaxed();
if (!rmap){ if (!rmap){
rmap = buildReverseMap(this->forwardIndex); rmap = buildReverseMap(this->forwardIndex);
if (!reverseMap.testAndSetRelease(0, rmap)) { if (!reverseMap.testAndSetRelease(0, rmap)) {
delete rmap; delete rmap;
rmap = reverseMap.load(); rmap = reverseMap.loadRelaxed();
} }
} }

View File

@ -80,15 +80,15 @@ enum GuardValues {
{ \ { \
struct HolderBase { \ struct HolderBase { \
~HolderBase() noexcept \ ~HolderBase() noexcept \
{ if (guard.load() == QtGlobalStatic::Initialized) \ { if (guard.loadRelaxed() == QtGlobalStatic::Initialized) \
guard.store(QtGlobalStatic::Destroyed); } \ guard.storeRelaxed(QtGlobalStatic::Destroyed); } \
}; \ }; \
static struct Holder : public HolderBase { \ static struct Holder : public HolderBase { \
Type value; \ Type value; \
Holder() \ Holder() \
noexcept(noexcept(Type ARGS)) \ noexcept(noexcept(Type ARGS)) \
: value ARGS \ : value ARGS \
{ guard.store(QtGlobalStatic::Initialized); } \ { guard.storeRelaxed(QtGlobalStatic::Initialized); } \
} holder; \ } holder; \
return &holder.value; \ return &holder.value; \
} }
@ -108,12 +108,12 @@ QT_BEGIN_NAMESPACE
int x = guard.loadAcquire(); \ int x = guard.loadAcquire(); \
if (Q_UNLIKELY(x >= QtGlobalStatic::Uninitialized)) { \ if (Q_UNLIKELY(x >= QtGlobalStatic::Uninitialized)) { \
QMutexLocker locker(&mutex); \ QMutexLocker locker(&mutex); \
if (guard.load() == QtGlobalStatic::Uninitialized) { \ if (guard.loadRelaxed() == QtGlobalStatic::Uninitialized) { \
d = new Type ARGS; \ d = new Type ARGS; \
static struct Cleanup { \ static struct Cleanup { \
~Cleanup() { \ ~Cleanup() { \
delete d; \ delete d; \
guard.store(QtGlobalStatic::Destroyed); \ guard.storeRelaxed(QtGlobalStatic::Destroyed); \
} \ } \
} cleanup; \ } cleanup; \
guard.storeRelease(QtGlobalStatic::Initialized); \ guard.storeRelease(QtGlobalStatic::Initialized); \
@ -129,8 +129,8 @@ struct QGlobalStatic
{ {
typedef T Type; typedef T Type;
bool isDestroyed() const { return guard.load() <= QtGlobalStatic::Destroyed; } bool isDestroyed() const { return guard.loadRelaxed() <= QtGlobalStatic::Destroyed; }
bool exists() const { return guard.load() == QtGlobalStatic::Initialized; } bool exists() const { return guard.loadRelaxed() == QtGlobalStatic::Initialized; }
operator Type *() { if (isDestroyed()) return nullptr; return innerFunction(); } operator Type *() { if (isDestroyed()) return nullptr; return innerFunction(); }
Type *operator()() { if (isDestroyed()) return nullptr; return innerFunction(); } Type *operator()() { if (isDestroyed()) return nullptr; return innerFunction(); }
Type *operator->() Type *operator->()

View File

@ -197,7 +197,7 @@ static bool isFatal(QtMsgType msgType)
// it's fatal if the current value is exactly 1, // it's fatal if the current value is exactly 1,
// otherwise decrement if it's non-zero // otherwise decrement if it's non-zero
return fatalCriticals.load() && fatalCriticals.fetchAndAddRelaxed(-1) == 1; return fatalCriticals.loadRelaxed() && fatalCriticals.fetchAndAddRelaxed(-1) == 1;
} }
if (msgType == QtWarningMsg || msgType == QtCriticalMsg) { if (msgType == QtWarningMsg || msgType == QtCriticalMsg) {
@ -205,7 +205,7 @@ static bool isFatal(QtMsgType msgType)
// it's fatal if the current value is exactly 1, // it's fatal if the current value is exactly 1,
// otherwise decrement if it's non-zero // otherwise decrement if it's non-zero
return fatalWarnings.load() && fatalWarnings.fetchAndAddRelaxed(-1) == 1; return fatalWarnings.loadRelaxed() && fatalWarnings.fetchAndAddRelaxed(-1) == 1;
} }
return false; return false;
@ -1814,11 +1814,11 @@ static void qt_message_print(QtMsgType msgType, const QMessageLogContext &contex
// itself, e.g. by using Qt API // itself, e.g. by using Qt API
if (grabMessageHandler()) { if (grabMessageHandler()) {
// prefer new message handler over the old one // prefer new message handler over the old one
if (msgHandler.load() == qDefaultMsgHandler if (msgHandler.loadRelaxed() == qDefaultMsgHandler
|| messageHandler.load() != qDefaultMessageHandler) { || messageHandler.loadRelaxed() != qDefaultMessageHandler) {
(*messageHandler.load())(msgType, context, message); (*messageHandler.loadRelaxed())(msgType, context, message);
} else { } else {
(*msgHandler.load())(msgType, message.toLocal8Bit().constData()); (*msgHandler.loadRelaxed())(msgType, message.toLocal8Bit().constData());
} }
ungrabMessageHandler(); ungrabMessageHandler();
} else { } else {

View File

@ -186,7 +186,7 @@ struct QRandomGenerator::SystemGenerator
#endif #endif
static void closeDevice() static void closeDevice()
{ {
int fd = self().fdp1.load() - 1; int fd = self().fdp1.loadRelaxed() - 1;
if (fd >= 0) if (fd >= 0)
qt_safe_close(fd); qt_safe_close(fd);
} }
@ -310,7 +310,7 @@ static void fallback_fill(quint32 *ptr, qsizetype left) noexcept
*end++ = quint32(nsecs); // 5 *end++ = quint32(nsecs); // 5
#endif #endif
if (quint32 v = seed.load()) if (quint32 v = seed.loadRelaxed())
*end++ = v; // 6 *end++ = v; // 6
#if QT_CONFIG(getauxval) #if QT_CONFIG(getauxval)

View File

@ -239,7 +239,7 @@ QLoggingCategory::QLoggingCategory(const char *category, QtMsgType enableForLeve
void QLoggingCategory::init(const char *category, QtMsgType severityLevel) void QLoggingCategory::init(const char *category, QtMsgType severityLevel)
{ {
enabled.store(0x01010101); // enabledDebug = enabledWarning = enabledCritical = true; enabled.storeRelaxed(0x01010101); // enabledDebug = enabledWarning = enabledCritical = true;
if (category) if (category)
name = category; name = category;
@ -342,10 +342,10 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
{ {
switch (type) { switch (type) {
#ifdef Q_ATOMIC_INT8_IS_SUPPORTED #ifdef Q_ATOMIC_INT8_IS_SUPPORTED
case QtDebugMsg: bools.enabledDebug.store(enable); break; case QtDebugMsg: bools.enabledDebug.storeRelaxed(enable); break;
case QtInfoMsg: bools.enabledInfo.store(enable); break; case QtInfoMsg: bools.enabledInfo.storeRelaxed(enable); break;
case QtWarningMsg: bools.enabledWarning.store(enable); break; case QtWarningMsg: bools.enabledWarning.storeRelaxed(enable); break;
case QtCriticalMsg: bools.enabledCritical.store(enable); break; case QtCriticalMsg: bools.enabledCritical.storeRelaxed(enable); break;
#else #else
case QtDebugMsg: setBoolLane(&enabled, enable, DebugShift); break; case QtDebugMsg: setBoolLane(&enabled, enable, DebugShift); break;
case QtInfoMsg: setBoolLane(&enabled, enable, InfoShift); break; case QtInfoMsg: setBoolLane(&enabled, enable, InfoShift); break;

View File

@ -58,15 +58,15 @@ public:
void setEnabled(QtMsgType type, bool enable); void setEnabled(QtMsgType type, bool enable);
#ifdef Q_ATOMIC_INT8_IS_SUPPORTED #ifdef Q_ATOMIC_INT8_IS_SUPPORTED
bool isDebugEnabled() const { return bools.enabledDebug.load(); } bool isDebugEnabled() const { return bools.enabledDebug.loadRelaxed(); }
bool isInfoEnabled() const { return bools.enabledInfo.load(); } bool isInfoEnabled() const { return bools.enabledInfo.loadRelaxed(); }
bool isWarningEnabled() const { return bools.enabledWarning.load(); } bool isWarningEnabled() const { return bools.enabledWarning.loadRelaxed(); }
bool isCriticalEnabled() const { return bools.enabledCritical.load(); } bool isCriticalEnabled() const { return bools.enabledCritical.loadRelaxed(); }
#else #else
bool isDebugEnabled() const { return enabled.load() >> DebugShift & 1; } bool isDebugEnabled() const { return enabled.loadRelaxed() >> DebugShift & 1; }
bool isInfoEnabled() const { return enabled.load() >> InfoShift & 1; } bool isInfoEnabled() const { return enabled.loadRelaxed() >> InfoShift & 1; }
bool isWarningEnabled() const { return enabled.load() >> WarningShift & 1; } bool isWarningEnabled() const { return enabled.loadRelaxed() >> WarningShift & 1; }
bool isCriticalEnabled() const { return enabled.load() >> CriticalShift & 1; } bool isCriticalEnabled() const { return enabled.loadRelaxed() >> CriticalShift & 1; }
#endif #endif
const char *categoryName() const { return name; } const char *categoryName() const { return name; }

View File

@ -220,7 +220,7 @@ public:
template<> Q_INLINE_TEMPLATE void QSharedDataPointer<QProcessEnvironmentPrivate>::detach() template<> Q_INLINE_TEMPLATE void QSharedDataPointer<QProcessEnvironmentPrivate>::detach()
{ {
if (d && d->ref.load() == 1) if (d && d->ref.loadRelaxed() == 1)
return; return;
QProcessEnvironmentPrivate *x = (d ? new QProcessEnvironmentPrivate(*d) QProcessEnvironmentPrivate *x = (d ? new QProcessEnvironmentPrivate(*d)
: new QProcessEnvironmentPrivate); : new QProcessEnvironmentPrivate);

View File

@ -3802,7 +3802,7 @@ void QUrl::detach()
*/ */
bool QUrl::isDetached() const bool QUrl::isDetached() const
{ {
return !d || d->ref.load() == 1; return !d || d->ref.loadRelaxed() == 1;
} }

View File

@ -189,7 +189,7 @@ public:
template<> void QSharedDataPointer<QUrlQueryPrivate>::detach() template<> void QSharedDataPointer<QUrlQueryPrivate>::detach()
{ {
if (d && d->ref.load() == 1) if (d && d->ref.loadRelaxed() == 1)
return; return;
QUrlQueryPrivate *x = (d ? new QUrlQueryPrivate(*d) QUrlQueryPrivate *x = (d ? new QUrlQueryPrivate(*d)
: new QUrlQueryPrivate); : new QUrlQueryPrivate);
@ -462,7 +462,7 @@ bool QUrlQuery::isEmpty() const
*/ */
bool QUrlQuery::isDetached() const bool QUrlQuery::isDetached() const
{ {
return d && d->ref.load() == 1; return d && d->ref.loadRelaxed() == 1;
} }
/*! /*!

View File

@ -77,7 +77,7 @@ QPersistentModelIndexData *QPersistentModelIndexData::create(const QModelIndex &
void QPersistentModelIndexData::destroy(QPersistentModelIndexData *data) void QPersistentModelIndexData::destroy(QPersistentModelIndexData *data)
{ {
Q_ASSERT(data); Q_ASSERT(data);
Q_ASSERT(data->ref.load() == 0); Q_ASSERT(data->ref.loadRelaxed() == 0);
QAbstractItemModel *model = const_cast<QAbstractItemModel *>(data->index.model()); QAbstractItemModel *model = const_cast<QAbstractItemModel *>(data->index.model());
// a valid persistent model index with a null model pointer can only happen if the model was destroyed // a valid persistent model index with a null model pointer can only happen if the model was destroyed
if (model) { if (model) {

View File

@ -170,7 +170,7 @@ QAbstractEventDispatcher::~QAbstractEventDispatcher()
QAbstractEventDispatcher *QAbstractEventDispatcher::instance(QThread *thread) QAbstractEventDispatcher *QAbstractEventDispatcher::instance(QThread *thread)
{ {
QThreadData *data = thread ? QThreadData::get2(thread) : QThreadData::current(); QThreadData *data = thread ? QThreadData::get2(thread) : QThreadData::current();
return data->eventDispatcher.load(); return data->eventDispatcher.loadRelaxed();
} }
/*! /*!

View File

@ -164,7 +164,7 @@ inline void qt_ignore_sigpipe()
{ {
// Set to ignore SIGPIPE once only. // Set to ignore SIGPIPE once only.
static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0); static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0);
if (!atom.load()) { if (!atom.loadRelaxed()) {
// More than one thread could turn off SIGPIPE at the same time // More than one thread could turn off SIGPIPE at the same time
// But that's acceptable because they all would be doing the same // But that's acceptable because they all would be doing the same
// action // action
@ -172,7 +172,7 @@ inline void qt_ignore_sigpipe()
memset(&noaction, 0, sizeof(noaction)); memset(&noaction, 0, sizeof(noaction));
noaction.sa_handler = SIG_IGN; noaction.sa_handler = SIG_IGN;
::sigaction(SIGPIPE, &noaction, nullptr); ::sigaction(SIGPIPE, &noaction, nullptr);
atom.store(1); atom.storeRelaxed(1);
} }
} }

View File

@ -552,8 +552,8 @@ void QCoreApplicationPrivate::eventDispatcherReady()
QBasicAtomicPointer<QThread> QCoreApplicationPrivate::theMainThread = Q_BASIC_ATOMIC_INITIALIZER(0); QBasicAtomicPointer<QThread> QCoreApplicationPrivate::theMainThread = Q_BASIC_ATOMIC_INITIALIZER(0);
QThread *QCoreApplicationPrivate::mainThread() QThread *QCoreApplicationPrivate::mainThread()
{ {
Q_ASSERT(theMainThread.load() != 0); Q_ASSERT(theMainThread.loadRelaxed() != 0);
return theMainThread.load(); return theMainThread.loadRelaxed();
} }
bool QCoreApplicationPrivate::threadRequiresCoreApplication() bool QCoreApplicationPrivate::threadRequiresCoreApplication()
@ -854,7 +854,7 @@ void QCoreApplicationPrivate::init()
#ifndef QT_NO_QOBJECT #ifndef QT_NO_QOBJECT
// use the event dispatcher created by the app programmer (if any) // use the event dispatcher created by the app programmer (if any)
Q_ASSERT(!eventDispatcher); Q_ASSERT(!eventDispatcher);
eventDispatcher = threadData->eventDispatcher.load(); eventDispatcher = threadData->eventDispatcher.loadRelaxed();
// otherwise we create one // otherwise we create one
if (!eventDispatcher) if (!eventDispatcher)
@ -1302,7 +1302,7 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags)
QThreadData *data = QThreadData::current(); QThreadData *data = QThreadData::current();
if (!data->hasEventDispatcher()) if (!data->hasEventDispatcher())
return; return;
data->eventDispatcher.load()->processEvents(flags); data->eventDispatcher.loadRelaxed()->processEvents(flags);
} }
/*! /*!
@ -1334,7 +1334,7 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int m
return; return;
QElapsedTimer start; QElapsedTimer start;
start.start(); start.start();
while (data->eventDispatcher.load()->processEvents(flags & ~QEventLoop::WaitForMoreEvents)) { while (data->eventDispatcher.loadRelaxed()->processEvents(flags & ~QEventLoop::WaitForMoreEvents)) {
if (start.elapsed() > ms) if (start.elapsed() > ms)
break; break;
} }
@ -1738,7 +1738,7 @@ void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int event_type
--data->postEventList.recursion; --data->postEventList.recursion;
if (!data->postEventList.recursion && !data->canWait && data->hasEventDispatcher()) if (!data->postEventList.recursion && !data->canWait && data->hasEventDispatcher())
data->eventDispatcher.load()->wakeUp(); data->eventDispatcher.loadRelaxed()->wakeUp();
// clear the global list, i.e. remove everything that was // clear the global list, i.e. remove everything that was
// delivered. // delivered.
@ -1989,7 +1989,7 @@ void QCoreApplicationPrivate::deref()
void QCoreApplicationPrivate::maybeQuit() void QCoreApplicationPrivate::maybeQuit()
{ {
if (quitLockRef.load() == 0 && in_exec && quitLockRefEnabled && shouldQuit()) if (quitLockRef.loadRelaxed() == 0 && in_exec && quitLockRefEnabled && shouldQuit())
QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::Quit)); QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::Quit));
} }
@ -2958,7 +2958,7 @@ bool QCoreApplication::hasPendingEvents()
QAbstractEventDispatcher *QCoreApplication::eventDispatcher() QAbstractEventDispatcher *QCoreApplication::eventDispatcher()
{ {
if (QCoreApplicationPrivate::theMainThread) if (QCoreApplicationPrivate::theMainThread)
return QCoreApplicationPrivate::theMainThread.load()->eventDispatcher(); return QCoreApplicationPrivate::theMainThread.loadRelaxed()->eventDispatcher();
return 0; return 0;
} }

View File

@ -424,7 +424,7 @@ struct QBasicAtomicBitField {
bool allocateSpecific(int which) noexcept bool allocateSpecific(int which) noexcept
{ {
QBasicAtomicInteger<uint> &entry = data[which / BitsPerInt]; QBasicAtomicInteger<uint> &entry = data[which / BitsPerInt];
const uint old = entry.load(); const uint old = entry.loadRelaxed();
const uint bit = 1U << (which % BitsPerInt); const uint bit = 1U << (which % BitsPerInt);
return !(old & bit) // wasn't taken return !(old & bit) // wasn't taken
&& entry.testAndSetRelaxed(old, old | bit); // still wasn't taken && entry.testAndSetRelaxed(old, old | bit); // still wasn't taken
@ -445,10 +445,10 @@ struct QBasicAtomicBitField {
// Then again, this should never execute many iterations, so // Then again, this should never execute many iterations, so
// leave like this for now: // leave like this for now:
for (uint i = next.load(); i < NumBits; ++i) { for (uint i = next.loadRelaxed(); i < NumBits; ++i) {
if (allocateSpecific(i)) { if (allocateSpecific(i)) {
// remember next (possibly) free id: // remember next (possibly) free id:
const uint oldNext = next.load(); const uint oldNext = next.loadRelaxed();
next.testAndSetRelaxed(oldNext, qMax(i + 1, oldNext)); next.testAndSetRelaxed(oldNext, qMax(i + 1, oldNext));
return i; return i;
} }

View File

@ -261,7 +261,7 @@ static gboolean postEventSourcePrepare(GSource *s, gint *timeout)
*timeout = canWait ? -1 : 0; *timeout = canWait ? -1 : 0;
GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s); GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);
source->d->wakeUpCalled = source->serialNumber.load() != source->lastSerialNumber; source->d->wakeUpCalled = source->serialNumber.loadRelaxed() != source->lastSerialNumber;
return !canWait || source->d->wakeUpCalled; return !canWait || source->d->wakeUpCalled;
} }
@ -273,7 +273,7 @@ static gboolean postEventSourceCheck(GSource *source)
static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer) static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer)
{ {
GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s); GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);
source->lastSerialNumber = source->serialNumber.load(); source->lastSerialNumber = source->serialNumber.loadRelaxed();
QCoreApplication::sendPostedEvents(); QCoreApplication::sendPostedEvents();
source->d->runTimersOnceWithNormalPriority(); source->d->runTimersOnceWithNormalPriority();
return true; // i dunno, george... return true; // i dunno, george...
@ -320,7 +320,7 @@ QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context)
// setup post event source // setup post event source
postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs, postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs,
sizeof(GPostEventSource))); sizeof(GPostEventSource)));
postEventSource->serialNumber.store(1); postEventSource->serialNumber.storeRelaxed(1);
postEventSource->d = this; postEventSource->d = this;
g_source_set_can_recurse(&postEventSource->source, true); g_source_set_can_recurse(&postEventSource->source, true);
g_source_attach(&postEventSource->source, mainContext); g_source_attach(&postEventSource->source, mainContext);

View File

@ -459,7 +459,7 @@ void QEventDispatcherUNIX::unregisterSocketNotifier(QSocketNotifier *notifier)
bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags) bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags)
{ {
Q_D(QEventDispatcherUNIX); Q_D(QEventDispatcherUNIX);
d->interrupt.store(0); d->interrupt.storeRelaxed(0);
// we are awake, broadcast it // we are awake, broadcast it
emit awake(); emit awake();
@ -470,13 +470,13 @@ bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags)
const bool wait_for_events = flags & QEventLoop::WaitForMoreEvents; const bool wait_for_events = flags & QEventLoop::WaitForMoreEvents;
const bool canWait = (d->threadData->canWaitLocked() const bool canWait = (d->threadData->canWaitLocked()
&& !d->interrupt.load() && !d->interrupt.loadRelaxed()
&& wait_for_events); && wait_for_events);
if (canWait) if (canWait)
emit aboutToBlock(); emit aboutToBlock();
if (d->interrupt.load()) if (d->interrupt.loadRelaxed())
return false; return false;
timespec *tm = nullptr; timespec *tm = nullptr;
@ -545,7 +545,7 @@ void QEventDispatcherUNIX::wakeUp()
void QEventDispatcherUNIX::interrupt() void QEventDispatcherUNIX::interrupt()
{ {
Q_D(QEventDispatcherUNIX); Q_D(QEventDispatcherUNIX);
d->interrupt.store(1); d->interrupt.storeRelaxed(1);
wakeUp(); wakeUp();
} }

View File

@ -247,7 +247,7 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA
Q_ASSERT(d != 0); Q_ASSERT(d != 0);
// Allow posting WM_QT_SENDPOSTEDEVENTS message. // Allow posting WM_QT_SENDPOSTEDEVENTS message.
d->wakeUps.store(0); d->wakeUps.storeRelaxed(0);
// We send posted events manually, if the window procedure was invoked // We send posted events manually, if the window procedure was invoked
// by the foreign event loop (e.g. from the native modal dialog). // by the foreign event loop (e.g. from the native modal dialog).
@ -526,7 +526,7 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags)
wakeUp(); // trigger a call to sendPostedEvents() wakeUp(); // trigger a call to sendPostedEvents()
} }
d->interrupt.store(false); d->interrupt.storeRelaxed(false);
emit awake(); emit awake();
// To prevent livelocks, send posted events once per iteration. // To prevent livelocks, send posted events once per iteration.
@ -545,7 +545,7 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags)
pHandles = &d->winEventNotifierActivatedEvent; pHandles = &d->winEventNotifierActivatedEvent;
} }
QVarLengthArray<MSG> processedTimers; QVarLengthArray<MSG> processedTimers;
while (!d->interrupt.load()) { while (!d->interrupt.loadRelaxed()) {
MSG msg; MSG msg;
bool haveMessage; bool haveMessage;
@ -590,7 +590,7 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags)
if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) { if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) {
// Set result to 'true', if the message was sent by wakeUp(). // Set result to 'true', if the message was sent by wakeUp().
if (msg.wParam == WMWP_QT_FROMWAKEUP) { if (msg.wParam == WMWP_QT_FROMWAKEUP) {
d->wakeUps.store(0); d->wakeUps.storeRelaxed(0);
retVal = true; retVal = true;
} }
needWM_QT_SENDPOSTEDEVENTS = true; needWM_QT_SENDPOSTEDEVENTS = true;
@ -639,7 +639,7 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags)
// still nothing - wait for message or signalled objects // still nothing - wait for message or signalled objects
canWait = (!retVal canWait = (!retVal
&& !d->interrupt.load() && !d->interrupt.loadRelaxed()
&& (flags & QEventLoop::WaitForMoreEvents)); && (flags & QEventLoop::WaitForMoreEvents));
if (canWait) { if (canWait) {
emit aboutToBlock(); emit aboutToBlock();
@ -949,7 +949,7 @@ void QEventDispatcherWin32::activateEventNotifiers()
for (int i = 0; i < d->winEventNotifierList.count(); ++i) { for (int i = 0; i < d->winEventNotifierList.count(); ++i) {
QWinEventNotifier *notifier = d->winEventNotifierList.at(i); QWinEventNotifier *notifier = d->winEventNotifierList.at(i);
QWinEventNotifierPrivate *nd = QWinEventNotifierPrivate::get(notifier); QWinEventNotifierPrivate *nd = QWinEventNotifierPrivate::get(notifier);
if (nd->signaledCount.load() != 0) { if (nd->signaledCount.loadRelaxed() != 0) {
--nd->signaledCount; --nd->signaledCount;
nd->unregisterWaitObject(); nd->unregisterWaitObject();
d->activateEventNotifier(notifier); d->activateEventNotifier(notifier);
@ -1014,7 +1014,7 @@ void QEventDispatcherWin32::wakeUp()
void QEventDispatcherWin32::interrupt() void QEventDispatcherWin32::interrupt()
{ {
Q_D(QEventDispatcherWin32); Q_D(QEventDispatcherWin32);
d->interrupt.store(true); d->interrupt.storeRelaxed(true);
wakeUp(); wakeUp();
} }

View File

@ -135,7 +135,7 @@ bool QEventLoop::processEvents(ProcessEventsFlags flags)
Q_D(QEventLoop); Q_D(QEventLoop);
if (!d->threadData->hasEventDispatcher()) if (!d->threadData->hasEventDispatcher())
return false; return false;
return d->threadData->eventDispatcher.load()->processEvents(flags); return d->threadData->eventDispatcher.loadRelaxed()->processEvents(flags);
} }
/*! /*!
@ -225,7 +225,7 @@ int QEventLoop::exec(ProcessEventsFlags flags)
processEvents(flags | WaitForMoreEvents | EventLoopExec); processEvents(flags | WaitForMoreEvents | EventLoopExec);
ref.exceptionCaught = false; ref.exceptionCaught = false;
return d->returnCode.load(); return d->returnCode.loadRelaxed();
} }
/*! /*!
@ -279,9 +279,9 @@ void QEventLoop::exit(int returnCode)
if (!d->threadData->hasEventDispatcher()) if (!d->threadData->hasEventDispatcher())
return; return;
d->returnCode.store(returnCode); d->returnCode.storeRelaxed(returnCode);
d->exit.storeRelease(true); d->exit.storeRelease(true);
d->threadData->eventDispatcher.load()->interrupt(); d->threadData->eventDispatcher.loadRelaxed()->interrupt();
#ifdef Q_OS_WASM #ifdef Q_OS_WASM
// QEventLoop::exec() never returns in emscripten. We implement approximate behavior here. // QEventLoop::exec() never returns in emscripten. We implement approximate behavior here.
@ -318,7 +318,7 @@ void QEventLoop::wakeUp()
Q_D(QEventLoop); Q_D(QEventLoop);
if (!d->threadData->hasEventDispatcher()) if (!d->threadData->hasEventDispatcher())
return; return;
d->threadData->eventDispatcher.load()->wakeUp(); d->threadData->eventDispatcher.loadRelaxed()->wakeUp();
} }

View File

@ -63,8 +63,8 @@ public:
inline QEventLoopPrivate() inline QEventLoopPrivate()
: inExec(false) : inExec(false)
{ {
returnCode.store(-1); returnCode.storeRelaxed(-1);
exit.store(true); exit.storeRelaxed(true);
} }
QAtomicInt quitLockRef; QAtomicInt quitLockRef;

View File

@ -1999,7 +1999,7 @@ struct QMetaTypeId< SINGLE_ARG_TEMPLATE<T> > \
static int qt_metatype_id() \ static int qt_metatype_id() \
{ \ { \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \ static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (const int id = metatype_id.load()) \ if (const int id = metatype_id.loadRelaxed()) \
return id; \ return id; \
const char *tName = QMetaType::typeName(qMetaTypeId<T>()); \ const char *tName = QMetaType::typeName(qMetaTypeId<T>()); \
Q_ASSERT(tName); \ Q_ASSERT(tName); \

View File

@ -222,7 +222,7 @@ QObjectPrivate::~QObjectPrivate()
if (Q_LIKELY(threadData->thread == QThread::currentThread())) { if (Q_LIKELY(threadData->thread == QThread::currentThread())) {
// unregister pending timers // unregister pending timers
if (threadData->hasEventDispatcher()) if (threadData->hasEventDispatcher())
threadData->eventDispatcher.load()->unregisterTimers(q_ptr); threadData->eventDispatcher.loadRelaxed()->unregisterTimers(q_ptr);
// release the timer ids back to the pool // release the timer ids back to the pool
for (int i = 0; i < extraData->runningTimers.size(); ++i) for (int i = 0; i < extraData->runningTimers.size(); ++i)
@ -268,17 +268,17 @@ bool QObjectPrivate::isSender(const QObject *receiver, const char *signal) const
{ {
Q_Q(const QObject); Q_Q(const QObject);
int signal_index = signalIndex(signal); int signal_index = signalIndex(signal);
ConnectionData *cd = connections.load(); ConnectionData *cd = connections.loadRelaxed();
if (signal_index < 0 || !cd) if (signal_index < 0 || !cd)
return false; return false;
QBasicMutexLocker locker(signalSlotLock(q)); QBasicMutexLocker locker(signalSlotLock(q));
if (signal_index < cd->signalVectorCount()) { if (signal_index < cd->signalVectorCount()) {
const QObjectPrivate::Connection *c = cd->signalVector.load()->at(signal_index).first.load(); const QObjectPrivate::Connection *c = cd->signalVector.loadRelaxed()->at(signal_index).first.loadRelaxed();
while (c) { while (c) {
if (c->receiver.load() == receiver) if (c->receiver.loadRelaxed() == receiver)
return true; return true;
c = c->nextConnectionList.load(); c = c->nextConnectionList.loadRelaxed();
} }
} }
return false; return false;
@ -289,17 +289,17 @@ QObjectList QObjectPrivate::receiverList(const char *signal) const
{ {
QObjectList returnValue; QObjectList returnValue;
int signal_index = signalIndex(signal); int signal_index = signalIndex(signal);
ConnectionData *cd = connections.load(); ConnectionData *cd = connections.loadRelaxed();
if (signal_index < 0 || !cd) if (signal_index < 0 || !cd)
return returnValue; return returnValue;
if (signal_index < cd->signalVectorCount()) { if (signal_index < cd->signalVectorCount()) {
const QObjectPrivate::Connection *c = cd->signalVector.load()->at(signal_index).first.load(); const QObjectPrivate::Connection *c = cd->signalVector.loadRelaxed()->at(signal_index).first.loadRelaxed();
while (c) { while (c) {
QObject *r = c->receiver.load(); QObject *r = c->receiver.loadRelaxed();
if (r) if (r)
returnValue << r; returnValue << r;
c = c->nextConnectionList.load(); c = c->nextConnectionList.loadRelaxed();
} }
} }
return returnValue; return returnValue;
@ -309,7 +309,7 @@ QObjectList QObjectPrivate::receiverList(const char *signal) const
QObjectList QObjectPrivate::senderList() const QObjectList QObjectPrivate::senderList() const
{ {
QObjectList returnValue; QObjectList returnValue;
ConnectionData *cd = connections.load(); ConnectionData *cd = connections.loadRelaxed();
if (cd) { if (cd) {
QBasicMutexLocker locker(signalSlotLock(q_func())); QBasicMutexLocker locker(signalSlotLock(q_func()));
for (Connection *c = cd->senders; c; c = c->next) for (Connection *c = cd->senders; c; c = c->next)
@ -332,24 +332,24 @@ void QObjectPrivate::addConnection(int signal, Connection *c)
{ {
Q_ASSERT(c->sender == q_ptr); Q_ASSERT(c->sender == q_ptr);
ensureConnectionData(); ensureConnectionData();
ConnectionData *cd = connections.load(); ConnectionData *cd = connections.loadRelaxed();
cd->resizeSignalVector(signal + 1); cd->resizeSignalVector(signal + 1);
ConnectionList &connectionList = cd->connectionsForSignal(signal); ConnectionList &connectionList = cd->connectionsForSignal(signal);
if (connectionList.last.load()) { if (connectionList.last.loadRelaxed()) {
Q_ASSERT(connectionList.last.load()->receiver.load()); Q_ASSERT(connectionList.last.loadRelaxed()->receiver.loadRelaxed());
connectionList.last.load()->nextConnectionList.store(c); connectionList.last.loadRelaxed()->nextConnectionList.storeRelaxed(c);
} else { } else {
connectionList.first.store(c); connectionList.first.storeRelaxed(c);
} }
c->id = ++cd->currentConnectionId; c->id = ++cd->currentConnectionId;
c->prevConnectionList = connectionList.last.load(); c->prevConnectionList = connectionList.last.loadRelaxed();
connectionList.last.store(c); connectionList.last.storeRelaxed(c);
QObjectPrivate *rd = QObjectPrivate::get(c->receiver.load()); QObjectPrivate *rd = QObjectPrivate::get(c->receiver.loadRelaxed());
rd->ensureConnectionData(); rd->ensureConnectionData();
c->prev = &(rd->connections.load()->senders); c->prev = &(rd->connections.loadRelaxed()->senders);
c->next = *c->prev; c->next = *c->prev;
*c->prev = c; *c->prev = c;
if (c->next) if (c->next)
@ -358,17 +358,17 @@ void QObjectPrivate::addConnection(int signal, Connection *c)
void QObjectPrivate::ConnectionData::removeConnection(QObjectPrivate::Connection *c) void QObjectPrivate::ConnectionData::removeConnection(QObjectPrivate::Connection *c)
{ {
Q_ASSERT(c->receiver.load()); Q_ASSERT(c->receiver.loadRelaxed());
ConnectionList &connections = signalVector.load()->at(c->signal_index); ConnectionList &connections = signalVector.loadRelaxed()->at(c->signal_index);
c->receiver.store(nullptr); c->receiver.storeRelaxed(nullptr);
QThreadData *td = c->receiverThreadData.load(); QThreadData *td = c->receiverThreadData.loadRelaxed();
if (td) if (td)
td->deref(); td->deref();
c->receiverThreadData.store(nullptr); c->receiverThreadData.storeRelaxed(nullptr);
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
bool found = false; bool found = false;
for (Connection *cc = connections.first.load(); cc; cc = cc->nextConnectionList.load()) { for (Connection *cc = connections.first.loadRelaxed(); cc; cc = cc->nextConnectionList.loadRelaxed()) {
if (cc == c) { if (cc == c) {
found = true; found = true;
break; break;
@ -383,29 +383,29 @@ void QObjectPrivate::ConnectionData::removeConnection(QObjectPrivate::Connection
c->next->prev = c->prev; c->next->prev = c->prev;
c->prev = nullptr; c->prev = nullptr;
if (connections.first.load() == c) if (connections.first.loadRelaxed() == c)
connections.first.store(c->nextConnectionList.load()); connections.first.storeRelaxed(c->nextConnectionList.loadRelaxed());
if (connections.last.load() == c) if (connections.last.loadRelaxed() == c)
connections.last.store(c->prevConnectionList); connections.last.storeRelaxed(c->prevConnectionList);
Q_ASSERT(signalVector.load()->at(c->signal_index).first.load() != c); Q_ASSERT(signalVector.loadRelaxed()->at(c->signal_index).first.loadRelaxed() != c);
Q_ASSERT(signalVector.load()->at(c->signal_index).last.load() != c); Q_ASSERT(signalVector.loadRelaxed()->at(c->signal_index).last.loadRelaxed() != c);
// keep c->nextConnectionList intact, as it might still get accessed by activate // keep c->nextConnectionList intact, as it might still get accessed by activate
Connection *n = c->nextConnectionList.load(); Connection *n = c->nextConnectionList.loadRelaxed();
if (n) if (n)
n->prevConnectionList = c->prevConnectionList; n->prevConnectionList = c->prevConnectionList;
if (c->prevConnectionList) if (c->prevConnectionList)
c->prevConnectionList->nextConnectionList.store(n); c->prevConnectionList->nextConnectionList.storeRelaxed(n);
c->prevConnectionList = nullptr; c->prevConnectionList = nullptr;
Q_ASSERT(c != orphaned.load()); Q_ASSERT(c != orphaned.loadRelaxed());
// add c to orphanedConnections // add c to orphanedConnections
c->nextInOrphanList = orphaned.load(); c->nextInOrphanList = orphaned.loadRelaxed();
orphaned.store(c); orphaned.storeRelaxed(c);
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
found = false; found = false;
for (Connection *cc = connections.first.load(); cc; cc = cc->nextConnectionList.load()) { for (Connection *cc = connections.first.loadRelaxed(); cc; cc = cc->nextConnectionList.loadRelaxed()) {
if (cc == c) { if (cc == c) {
found = true; found = true;
break; break;
@ -427,8 +427,8 @@ void QObjectPrivate::ConnectionData::cleanOrphanedConnectionsImpl(QObject *sende
// Since ref == 1, no activate() is in process since we locked the mutex. That implies, // Since ref == 1, no activate() is in process since we locked the mutex. That implies,
// that nothing can reference the orphaned connection objects anymore and they can // that nothing can reference the orphaned connection objects anymore and they can
// be safely deleted // be safely deleted
c = orphaned.load(); c = orphaned.loadRelaxed();
orphaned.store(nullptr); orphaned.storeRelaxed(nullptr);
} }
deleteOrphaned(c); deleteOrphaned(c);
} }
@ -443,7 +443,7 @@ void QObjectPrivate::ConnectionData::deleteOrphaned(QObjectPrivate::ConnectionOr
} else { } else {
QObjectPrivate::Connection *c = static_cast<Connection *>(o); QObjectPrivate::Connection *c = static_cast<Connection *>(o);
next = c->nextInOrphanList; next = c->nextInOrphanList;
Q_ASSERT(!c->receiver.load()); Q_ASSERT(!c->receiver.loadRelaxed());
Q_ASSERT(!c->prev); Q_ASSERT(!c->prev);
c->freeSlotObject(); c->freeSlotObject();
c->deref(); c->deref();
@ -463,22 +463,22 @@ bool QObjectPrivate::isSignalConnected(uint signalIndex, bool checkDeclarative)
if (checkDeclarative && isDeclarativeSignalConnected(signalIndex)) if (checkDeclarative && isDeclarativeSignalConnected(signalIndex))
return true; return true;
ConnectionData *cd = connections.load(); ConnectionData *cd = connections.loadRelaxed();
if (!cd) if (!cd)
return false; return false;
SignalVector *signalVector = cd->signalVector.load(); SignalVector *signalVector = cd->signalVector.loadRelaxed();
if (!signalVector) if (!signalVector)
return false; return false;
if (signalVector->at(-1).first.load()) if (signalVector->at(-1).first.loadRelaxed())
return true; return true;
if (signalIndex < uint(cd->signalVectorCount())) { if (signalIndex < uint(cd->signalVectorCount())) {
const QObjectPrivate::Connection *c = signalVector->at(signalIndex).first.load(); const QObjectPrivate::Connection *c = signalVector->at(signalIndex).first.loadRelaxed();
while (c) { while (c) {
if (c->receiver.load()) if (c->receiver.loadRelaxed())
return true; return true;
c = c->nextConnectionList.load(); c = c->nextConnectionList.loadRelaxed();
} }
} }
return false; return false;
@ -486,10 +486,10 @@ bool QObjectPrivate::isSignalConnected(uint signalIndex, bool checkDeclarative)
bool QObjectPrivate::maybeSignalConnected(uint signalIndex) const bool QObjectPrivate::maybeSignalConnected(uint signalIndex) const
{ {
ConnectionData *cd = connections.load(); ConnectionData *cd = connections.loadRelaxed();
if (!cd) if (!cd)
return false; return false;
SignalVector *signalVector = cd->signalVector.load(); SignalVector *signalVector = cd->signalVector.loadRelaxed();
if (!signalVector) if (!signalVector)
return false; return false;
@ -944,15 +944,15 @@ QObject::~QObject()
d->wasDeleted = true; d->wasDeleted = true;
d->blockSig = 0; // unblock signals so we always emit destroyed() d->blockSig = 0; // unblock signals so we always emit destroyed()
QtSharedPointer::ExternalRefCountData *sharedRefcount = d->sharedRefcount.load(); QtSharedPointer::ExternalRefCountData *sharedRefcount = d->sharedRefcount.loadRelaxed();
if (sharedRefcount) { if (sharedRefcount) {
if (sharedRefcount->strongref.load() > 0) { if (sharedRefcount->strongref.loadRelaxed() > 0) {
qWarning("QObject: shared QObject was deleted directly. The program is malformed and may crash."); qWarning("QObject: shared QObject was deleted directly. The program is malformed and may crash.");
// but continue deleting, it's too late to stop anyway // but continue deleting, it's too late to stop anyway
} }
// indicate to all QWeakPointers that this QObject has now been deleted // indicate to all QWeakPointers that this QObject has now been deleted
sharedRefcount->strongref.store(0); sharedRefcount->strongref.storeRelaxed(0);
if (!sharedRefcount->weakref.deref()) if (!sharedRefcount->weakref.deref())
delete sharedRefcount; delete sharedRefcount;
} }
@ -971,7 +971,7 @@ QObject::~QObject()
} }
} }
QObjectPrivate::ConnectionData *cd = d->connections.load(); QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed();
if (cd) { if (cd) {
if (cd->currentSender) { if (cd->currentSender) {
cd->currentSender->receiverDeleted(); cd->currentSender->receiverDeleted();
@ -986,14 +986,14 @@ QObject::~QObject()
for (int signal = -1; signal < receiverCount; ++signal) { for (int signal = -1; signal < receiverCount; ++signal) {
QObjectPrivate::ConnectionList &connectionList = cd->connectionsForSignal(signal); QObjectPrivate::ConnectionList &connectionList = cd->connectionsForSignal(signal);
while (QObjectPrivate::Connection *c = connectionList.first.load()) { while (QObjectPrivate::Connection *c = connectionList.first.loadRelaxed()) {
Q_ASSERT(c->receiver); Q_ASSERT(c->receiver);
QBasicMutex *m = signalSlotLock(c->receiver.load()); QBasicMutex *m = signalSlotLock(c->receiver.loadRelaxed());
bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m); bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m);
if (c->receiver) { if (c->receiver) {
cd->removeConnection(c); cd->removeConnection(c);
Q_ASSERT(connectionList.first.load() != c); Q_ASSERT(connectionList.first.loadRelaxed() != c);
} }
if (needToUnlock) if (needToUnlock)
m->unlock(); m->unlock();
@ -1019,7 +1019,7 @@ QObject::~QObject()
continue; continue;
} }
QObjectPrivate::ConnectionData *senderData = sender->d_func()->connections.load(); QObjectPrivate::ConnectionData *senderData = sender->d_func()->connections.loadRelaxed();
Q_ASSERT(senderData); Q_ASSERT(senderData);
QtPrivate::QSlotObjectBase *slotObj = nullptr; QtPrivate::QSlotObjectBase *slotObj = nullptr;
@ -1041,11 +1041,11 @@ QObject::~QObject()
// invalidate all connections on the object and make sure // invalidate all connections on the object and make sure
// activate() will skip them // activate() will skip them
cd->currentConnectionId.store(0); cd->currentConnectionId.storeRelaxed(0);
} }
if (cd && !cd->ref.deref()) if (cd && !cd->ref.deref())
delete cd; delete cd;
d->connections.store(nullptr); d->connections.storeRelaxed(nullptr);
if (!d->children.isEmpty()) if (!d->children.isEmpty())
d->deleteChildren(); d->deleteChildren();
@ -1065,7 +1065,7 @@ QObject::~QObject()
QObjectPrivate::Connection::~Connection() QObjectPrivate::Connection::~Connection()
{ {
if (ownArgumentTypes) { if (ownArgumentTypes) {
const int *v = argumentTypes.load(); const int *v = argumentTypes.loadRelaxed();
if (v != &DIRECT_CONNECTION_ONLY) if (v != &DIRECT_CONNECTION_ONLY)
delete [] v; delete [] v;
} }
@ -1274,7 +1274,7 @@ bool QObject::event(QEvent *e)
{ {
QAbstractMetaCallEvent *mce = static_cast<QAbstractMetaCallEvent*>(e); QAbstractMetaCallEvent *mce = static_cast<QAbstractMetaCallEvent*>(e);
if (!d_func()->connections.load()) { if (!d_func()->connections.loadRelaxed()) {
QBasicMutexLocker locker(signalSlotLock(this)); QBasicMutexLocker locker(signalSlotLock(this));
d_func()->ensureConnectionData(); d_func()->ensureConnectionData();
} }
@ -1287,7 +1287,7 @@ bool QObject::event(QEvent *e)
case QEvent::ThreadChange: { case QEvent::ThreadChange: {
Q_D(QObject); Q_D(QObject);
QThreadData *threadData = d->threadData; QThreadData *threadData = d->threadData;
QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher.load(); QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher.loadRelaxed();
if (eventDispatcher) { if (eventDispatcher) {
QList<QAbstractEventDispatcher::TimerInfo> timers = eventDispatcher->registeredTimers(this); QList<QAbstractEventDispatcher::TimerInfo> timers = eventDispatcher->registeredTimers(this);
if (!timers.isEmpty()) { if (!timers.isEmpty()) {
@ -1522,7 +1522,7 @@ void QObject::moveToThread(QThread *targetThread)
} else if (d->threadData != currentData) { } else if (d->threadData != currentData) {
qWarning("QObject::moveToThread: Current thread (%p) is not the object's thread (%p).\n" qWarning("QObject::moveToThread: Current thread (%p) is not the object's thread (%p).\n"
"Cannot move to target thread (%p)\n", "Cannot move to target thread (%p)\n",
currentData->thread.load(), d->threadData->thread.load(), targetData ? targetData->thread.load() : nullptr); currentData->thread.loadRelaxed(), d->threadData->thread.loadRelaxed(), targetData ? targetData->thread.loadRelaxed() : nullptr);
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
qWarning("You might be loading two sets of Qt binaries into the same process. " qWarning("You might be loading two sets of Qt binaries into the same process. "
@ -1587,11 +1587,11 @@ void QObjectPrivate::setThreadData_helper(QThreadData *currentData, QThreadData
} }
if (eventsMoved > 0 && targetData->hasEventDispatcher()) { if (eventsMoved > 0 && targetData->hasEventDispatcher()) {
targetData->canWait = false; targetData->canWait = false;
targetData->eventDispatcher.load()->wakeUp(); targetData->eventDispatcher.loadRelaxed()->wakeUp();
} }
// the current emitting thread shouldn't restore currentSender after calling moveToThread() // the current emitting thread shouldn't restore currentSender after calling moveToThread()
ConnectionData *cd = connections.load(); ConnectionData *cd = connections.loadRelaxed();
if (cd) { if (cd) {
if (cd->currentSender) { if (cd->currentSender) {
cd->currentSender->receiverDeleted(); cd->currentSender->receiverDeleted();
@ -1602,14 +1602,14 @@ void QObjectPrivate::setThreadData_helper(QThreadData *currentData, QThreadData
if (cd) { if (cd) {
auto *c = cd->senders; auto *c = cd->senders;
while (c) { while (c) {
QObject *r = c->receiver.load(); QObject *r = c->receiver.loadRelaxed();
if (r) { if (r) {
Q_ASSERT(r == q); Q_ASSERT(r == q);
targetData->ref(); targetData->ref();
QThreadData *old = c->receiverThreadData.load(); QThreadData *old = c->receiverThreadData.loadRelaxed();
if (old) if (old)
old->deref(); old->deref();
c->receiverThreadData.store(targetData); c->receiverThreadData.storeRelaxed(targetData);
} }
c = c->next; c = c->next;
} }
@ -1632,7 +1632,7 @@ void QObjectPrivate::_q_reregisterTimers(void *pointer)
{ {
Q_Q(QObject); Q_Q(QObject);
QList<QAbstractEventDispatcher::TimerInfo> *timerList = reinterpret_cast<QList<QAbstractEventDispatcher::TimerInfo> *>(pointer); QList<QAbstractEventDispatcher::TimerInfo> *timerList = reinterpret_cast<QList<QAbstractEventDispatcher::TimerInfo> *>(pointer);
QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher.load(); QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher.loadRelaxed();
for (int i = 0; i < timerList->size(); ++i) { for (int i = 0; i < timerList->size(); ++i) {
const QAbstractEventDispatcher::TimerInfo &ti = timerList->at(i); const QAbstractEventDispatcher::TimerInfo &ti = timerList->at(i);
eventDispatcher->registerTimer(ti.timerId, ti.interval, ti.timerType, q); eventDispatcher->registerTimer(ti.timerId, ti.interval, ti.timerType, q);
@ -1698,7 +1698,7 @@ int QObject::startTimer(int interval, Qt::TimerType timerType)
qWarning("QObject::startTimer: Timers cannot be started from another thread"); qWarning("QObject::startTimer: Timers cannot be started from another thread");
return 0; return 0;
} }
int timerId = d->threadData->eventDispatcher.load()->registerTimer(interval, timerType, this); int timerId = d->threadData->eventDispatcher.loadRelaxed()->registerTimer(interval, timerType, this);
if (!d->extraData) if (!d->extraData)
d->extraData = new QObjectPrivate::ExtraData; d->extraData = new QObjectPrivate::ExtraData;
d->extraData->runningTimers.append(timerId); d->extraData->runningTimers.append(timerId);
@ -1773,7 +1773,7 @@ void QObject::killTimer(int id)
} }
if (d->threadData->hasEventDispatcher()) if (d->threadData->hasEventDispatcher())
d->threadData->eventDispatcher.load()->unregisterTimer(id); d->threadData->eventDispatcher.loadRelaxed()->unregisterTimer(id);
d->extraData->runningTimers.remove(at); d->extraData->runningTimers.remove(at);
QAbstractEventDispatcherPrivate::releaseTimerId(id); QAbstractEventDispatcherPrivate::releaseTimerId(id);
@ -2442,7 +2442,7 @@ QObject *QObject::sender() const
Q_D(const QObject); Q_D(const QObject);
QBasicMutexLocker locker(signalSlotLock(this)); QBasicMutexLocker locker(signalSlotLock(this));
QObjectPrivate::ConnectionData *cd = d->connections.load(); QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed();
if (!cd || !cd->currentSender) if (!cd || !cd->currentSender)
return nullptr; return nullptr;
@ -2484,7 +2484,7 @@ int QObject::senderSignalIndex() const
Q_D(const QObject); Q_D(const QObject);
QBasicMutexLocker locker(signalSlotLock(this)); QBasicMutexLocker locker(signalSlotLock(this));
QObjectPrivate::ConnectionData *cd = d->connections.load(); QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed();
if (!cd || !cd->currentSender) if (!cd || !cd->currentSender)
return -1; return -1;
@ -2547,13 +2547,13 @@ int QObject::receivers(const char *signal) const
signal_index); signal_index);
} }
QObjectPrivate::ConnectionData *cd = d->connections.load(); QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed();
QBasicMutexLocker locker(signalSlotLock(this)); QBasicMutexLocker locker(signalSlotLock(this));
if (cd && signal_index < cd->signalVectorCount()) { if (cd && signal_index < cd->signalVectorCount()) {
const QObjectPrivate::Connection *c = cd->signalVector.load()->at(signal_index).first.load(); const QObjectPrivate::Connection *c = cd->signalVector.loadRelaxed()->at(signal_index).first.loadRelaxed();
while (c) { while (c) {
receivers += c->receiver.load() ? 1 : 0; receivers += c->receiver.loadRelaxed() ? 1 : 0;
c = c->nextConnectionList.load(); c = c->nextConnectionList.loadRelaxed();
} }
} }
} }
@ -3362,17 +3362,17 @@ QObjectPrivate::Connection *QMetaObjectPrivate::connect(const QObject *sender,
QOrderedMutexLocker locker(signalSlotLock(sender), QOrderedMutexLocker locker(signalSlotLock(sender),
signalSlotLock(receiver)); signalSlotLock(receiver));
QObjectPrivate::ConnectionData *scd = QObjectPrivate::get(s)->connections.load(); QObjectPrivate::ConnectionData *scd = QObjectPrivate::get(s)->connections.loadRelaxed();
if (type & Qt::UniqueConnection && scd) { if (type & Qt::UniqueConnection && scd) {
if (scd->signalVectorCount() > signal_index) { if (scd->signalVectorCount() > signal_index) {
const QObjectPrivate::Connection *c2 = scd->signalVector.load()->at(signal_index).first.load(); const QObjectPrivate::Connection *c2 = scd->signalVector.loadRelaxed()->at(signal_index).first.loadRelaxed();
int method_index_absolute = method_index + method_offset; int method_index_absolute = method_index + method_offset;
while (c2) { while (c2) {
if (!c2->isSlotObject && c2->receiver.load() == receiver && c2->method() == method_index_absolute) if (!c2->isSlotObject && c2->receiver.loadRelaxed() == receiver && c2->method() == method_index_absolute)
return nullptr; return nullptr;
c2 = c2->nextConnectionList.load(); c2 = c2->nextConnectionList.loadRelaxed();
} }
} }
type &= Qt::UniqueConnection - 1; type &= Qt::UniqueConnection - 1;
@ -3381,15 +3381,15 @@ QObjectPrivate::Connection *QMetaObjectPrivate::connect(const QObject *sender,
QScopedPointer<QObjectPrivate::Connection> c(new QObjectPrivate::Connection); QScopedPointer<QObjectPrivate::Connection> c(new QObjectPrivate::Connection);
c->sender = s; c->sender = s;
c->signal_index = signal_index; c->signal_index = signal_index;
c->receiver.store(r); c->receiver.storeRelaxed(r);
QThreadData *td = r->d_func()->threadData; QThreadData *td = r->d_func()->threadData;
td->ref(); td->ref();
c->receiverThreadData.store(td); c->receiverThreadData.storeRelaxed(td);
c->method_relative = method_index; c->method_relative = method_index;
c->method_offset = method_offset; c->method_offset = method_offset;
c->connectionType = type; c->connectionType = type;
c->isSlotObject = false; c->isSlotObject = false;
c->argumentTypes.store(types); c->argumentTypes.storeRelaxed(types);
c->callFunction = callFunction; c->callFunction = callFunction;
QObjectPrivate::get(s)->addConnection(signal_index, c.data()); QObjectPrivate::get(s)->addConnection(signal_index, c.data());
@ -3442,9 +3442,9 @@ bool QMetaObjectPrivate::disconnectHelper(QObjectPrivate::ConnectionData *connec
bool success = false; bool success = false;
auto &connectionList = connections->connectionsForSignal(signalIndex); auto &connectionList = connections->connectionsForSignal(signalIndex);
auto *c = connectionList.first.load(); auto *c = connectionList.first.loadRelaxed();
while (c) { while (c) {
QObject *r = c->receiver.load(); QObject *r = c->receiver.loadRelaxed();
if (r && (receiver == nullptr || (r == receiver if (r && (receiver == nullptr || (r == receiver
&& (method_index < 0 || (!c->isSlotObject && c->method() == method_index)) && (method_index < 0 || (!c->isSlotObject && c->method() == method_index))
&& (slot == nullptr || (c->isSlotObject && c->slotObj->compare(slot)))))) { && (slot == nullptr || (c->isSlotObject && c->slotObj->compare(slot)))))) {
@ -3455,7 +3455,7 @@ bool QMetaObjectPrivate::disconnectHelper(QObjectPrivate::ConnectionData *connec
// need to relock this receiver and sender in the correct order // need to relock this receiver and sender in the correct order
needToUnlock = QOrderedMutexLocker::relock(senderMutex, receiverMutex); needToUnlock = QOrderedMutexLocker::relock(senderMutex, receiverMutex);
} }
if (c->receiver.load()) if (c->receiver.loadRelaxed())
connections->removeConnection(c); connections->removeConnection(c);
if (needToUnlock) if (needToUnlock)
@ -3466,7 +3466,7 @@ bool QMetaObjectPrivate::disconnectHelper(QObjectPrivate::ConnectionData *connec
if (disconnectType == DisconnectOne) if (disconnectType == DisconnectOne)
return success; return success;
} }
c = c->nextConnectionList.load(); c = c->nextConnectionList.loadRelaxed();
} }
return success; return success;
} }
@ -3488,7 +3488,7 @@ bool QMetaObjectPrivate::disconnect(const QObject *sender,
QBasicMutex *senderMutex = signalSlotLock(sender); QBasicMutex *senderMutex = signalSlotLock(sender);
QBasicMutexLocker locker(senderMutex); QBasicMutexLocker locker(senderMutex);
QObjectPrivate::ConnectionData *scd = QObjectPrivate::get(s)->connections.load(); QObjectPrivate::ConnectionData *scd = QObjectPrivate::get(s)->connections.loadRelaxed();
if (!scd) if (!scd)
return false; return false;
@ -3630,7 +3630,7 @@ void QMetaObject::connectSlotsByName(QObject *o)
*/ */
static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connection *c, void **argv) static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connection *c, void **argv)
{ {
const int *argumentTypes = c->argumentTypes.load(); const int *argumentTypes = c->argumentTypes.loadRelaxed();
if (!argumentTypes) { if (!argumentTypes) {
QMetaMethod m = QMetaObjectPrivate::signal(sender->metaObject(), signal); QMetaMethod m = QMetaObjectPrivate::signal(sender->metaObject(), signal);
argumentTypes = queuedConnectionTypes(m.parameterTypes()); argumentTypes = queuedConnectionTypes(m.parameterTypes());
@ -3639,7 +3639,7 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
if (!c->argumentTypes.testAndSetOrdered(0, argumentTypes)) { if (!c->argumentTypes.testAndSetOrdered(0, argumentTypes)) {
if (argumentTypes != &DIRECT_CONNECTION_ONLY) if (argumentTypes != &DIRECT_CONNECTION_ONLY)
delete [] argumentTypes; delete [] argumentTypes;
argumentTypes = c->argumentTypes.load(); argumentTypes = c->argumentTypes.loadRelaxed();
} }
} }
if (argumentTypes == &DIRECT_CONNECTION_ONLY) // cannot activate if (argumentTypes == &DIRECT_CONNECTION_ONLY) // cannot activate
@ -3662,8 +3662,8 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
args[n] = QMetaType::create(types[n], argv[n]); args[n] = QMetaType::create(types[n], argv[n]);
} }
QBasicMutexLocker locker(signalSlotLock(c->receiver.load())); QBasicMutexLocker locker(signalSlotLock(c->receiver.loadRelaxed()));
if (!c->receiver.load()) { if (!c->receiver.loadRelaxed()) {
// the connection has been disconnected before we got the lock // the connection has been disconnected before we got the lock
locker.unlock(); locker.unlock();
for (int n = 1; n < nargs; ++n) for (int n = 1; n < nargs; ++n)
@ -3676,7 +3676,7 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
QMetaCallEvent *ev = c->isSlotObject ? QMetaCallEvent *ev = c->isSlotObject ?
new QMetaCallEvent(c->slotObj, sender, signal, nargs, types, args) : new QMetaCallEvent(c->slotObj, sender, signal, nargs, types, args) :
new QMetaCallEvent(c->method_offset, c->method_relative, c->callFunction, sender, signal, nargs, types, args); new QMetaCallEvent(c->method_offset, c->method_relative, c->callFunction, sender, signal, nargs, types, args);
QCoreApplication::postEvent(c->receiver.load(), ev); QCoreApplication::postEvent(c->receiver.loadRelaxed(), ev);
} }
template <bool callbacks_enabled> template <bool callbacks_enabled>
@ -3717,8 +3717,8 @@ void doActivate(QObject *sender, int signal_index, void **argv)
bool senderDeleted = false; bool senderDeleted = false;
{ {
Q_ASSERT(sp->connections); Q_ASSERT(sp->connections);
QObjectPrivate::ConnectionDataPointer connections(sp->connections.load()); QObjectPrivate::ConnectionDataPointer connections(sp->connections.loadRelaxed());
QObjectPrivate::SignalVector *signalVector = connections->signalVector.load(); QObjectPrivate::SignalVector *signalVector = connections->signalVector.loadRelaxed();
const QObjectPrivate::ConnectionList *list; const QObjectPrivate::ConnectionList *list;
if (signal_index < signalVector->count()) if (signal_index < signalVector->count())
@ -3727,32 +3727,32 @@ void doActivate(QObject *sender, int signal_index, void **argv)
list = &signalVector->at(-1); list = &signalVector->at(-1);
Qt::HANDLE currentThreadId = QThread::currentThreadId(); Qt::HANDLE currentThreadId = QThread::currentThreadId();
bool inSenderThread = currentThreadId == QObjectPrivate::get(sender)->threadData->threadId.load(); bool inSenderThread = currentThreadId == QObjectPrivate::get(sender)->threadData->threadId.loadRelaxed();
// We need to check against the highest connection id to ensure that signals added // We need to check against the highest connection id to ensure that signals added
// during the signal emission are not emitted in this emission. // during the signal emission are not emitted in this emission.
uint highestConnectionId = connections->currentConnectionId.load(); uint highestConnectionId = connections->currentConnectionId.loadRelaxed();
do { do {
QObjectPrivate::Connection *c = list->first.load(); QObjectPrivate::Connection *c = list->first.loadRelaxed();
if (!c) if (!c)
continue; continue;
do { do {
QObject * const receiver = c->receiver.load(); QObject * const receiver = c->receiver.loadRelaxed();
if (!receiver) if (!receiver)
continue; continue;
QThreadData *td = c->receiverThreadData.load(); QThreadData *td = c->receiverThreadData.loadRelaxed();
if (!td) if (!td)
continue; continue;
bool receiverInSameThread; bool receiverInSameThread;
if (inSenderThread) { if (inSenderThread) {
receiverInSameThread = currentThreadId == td->threadId.load(); receiverInSameThread = currentThreadId == td->threadId.loadRelaxed();
} else { } else {
// need to lock before reading the threadId, because moveToThread() could interfere // need to lock before reading the threadId, because moveToThread() could interfere
QMutexLocker lock(signalSlotLock(receiver)); QMutexLocker lock(signalSlotLock(receiver));
receiverInSameThread = currentThreadId == td->threadId.load(); receiverInSameThread = currentThreadId == td->threadId.loadRelaxed();
} }
@ -3825,17 +3825,17 @@ void doActivate(QObject *sender, int signal_index, void **argv)
if (callbacks_enabled && signal_spy_set->slot_end_callback != nullptr) if (callbacks_enabled && signal_spy_set->slot_end_callback != nullptr)
signal_spy_set->slot_end_callback(receiver, method); signal_spy_set->slot_end_callback(receiver, method);
} }
} while ((c = c->nextConnectionList.load()) != nullptr && c->id <= highestConnectionId); } while ((c = c->nextConnectionList.loadRelaxed()) != nullptr && c->id <= highestConnectionId);
} while (list != &signalVector->at(-1) && } while (list != &signalVector->at(-1) &&
//start over for all signals; //start over for all signals;
((list = &signalVector->at(-1)), true)); ((list = &signalVector->at(-1)), true));
if (connections->currentConnectionId.load() == 0) if (connections->currentConnectionId.loadRelaxed() == 0)
senderDeleted = true; senderDeleted = true;
} }
if (!senderDeleted) if (!senderDeleted)
sp->connections.load()->cleanOrphanedConnections(sender); sp->connections.loadRelaxed()->cleanOrphanedConnections(sender);
if (callbacks_enabled && signal_spy_set->signal_end_callback != nullptr) if (callbacks_enabled && signal_spy_set->signal_end_callback != nullptr)
signal_spy_set->signal_end_callback(sender, signal_index); signal_spy_set->signal_end_callback(sender, signal_index);
@ -3849,7 +3849,7 @@ void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_sign
{ {
int signal_index = local_signal_index + QMetaObjectPrivate::signalOffset(m); int signal_index = local_signal_index + QMetaObjectPrivate::signalOffset(m);
if (Q_UNLIKELY(qt_signal_spy_callback_set.load())) if (Q_UNLIKELY(qt_signal_spy_callback_set.loadRelaxed()))
doActivate<true>(sender, signal_index, argv); doActivate<true>(sender, signal_index, argv);
else else
doActivate<false>(sender, signal_index, argv); doActivate<false>(sender, signal_index, argv);
@ -3862,7 +3862,7 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i
{ {
int signal_index = signalOffset + local_signal_index; int signal_index = signalOffset + local_signal_index;
if (Q_UNLIKELY(qt_signal_spy_callback_set.load())) if (Q_UNLIKELY(qt_signal_spy_callback_set.loadRelaxed()))
doActivate<true>(sender, signal_index, argv); doActivate<true>(sender, signal_index, argv);
else else
doActivate<false>(sender, signal_index, argv); doActivate<false>(sender, signal_index, argv);
@ -4131,11 +4131,11 @@ void QObject::dumpObjectInfo() const
// first, look for connections where this object is the sender // first, look for connections where this object is the sender
qDebug(" SIGNALS OUT"); qDebug(" SIGNALS OUT");
QObjectPrivate::ConnectionData *cd = d->connections.load(); QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed();
if (cd && cd->signalVectorCount()) { if (cd && cd->signalVectorCount()) {
QObjectPrivate::SignalVector *signalVector = cd->signalVector.load(); QObjectPrivate::SignalVector *signalVector = cd->signalVector.loadRelaxed();
for (int signal_index = 0; signal_index < signalVector->count(); ++signal_index) { for (int signal_index = 0; signal_index < signalVector->count(); ++signal_index) {
const QObjectPrivate::Connection *c = signalVector->at(signal_index).first.load(); const QObjectPrivate::Connection *c = signalVector->at(signal_index).first.loadRelaxed();
if (!c) if (!c)
continue; continue;
const QMetaMethod signal = QMetaObjectPrivate::signal(metaObject(), signal_index); const QMetaMethod signal = QMetaObjectPrivate::signal(metaObject(), signal_index);
@ -4143,23 +4143,23 @@ void QObject::dumpObjectInfo() const
// receivers // receivers
while (c) { while (c) {
if (!c->receiver.load()) { if (!c->receiver.loadRelaxed()) {
qDebug(" <Disconnected receiver>"); qDebug(" <Disconnected receiver>");
c = c->nextConnectionList.load(); c = c->nextConnectionList.loadRelaxed();
continue; continue;
} }
if (c->isSlotObject) { if (c->isSlotObject) {
qDebug(" <functor or function pointer>"); qDebug(" <functor or function pointer>");
c = c->nextConnectionList.load(); c = c->nextConnectionList.loadRelaxed();
continue; continue;
} }
const QMetaObject *receiverMetaObject = c->receiver.load()->metaObject(); const QMetaObject *receiverMetaObject = c->receiver.loadRelaxed()->metaObject();
const QMetaMethod method = receiverMetaObject->method(c->method()); const QMetaMethod method = receiverMetaObject->method(c->method());
qDebug(" --> %s::%s %s", qDebug(" --> %s::%s %s",
receiverMetaObject->className(), receiverMetaObject->className(),
c->receiver.load()->objectName().isEmpty() ? "unnamed" : qPrintable(c->receiver.load()->objectName()), c->receiver.loadRelaxed()->objectName().isEmpty() ? "unnamed" : qPrintable(c->receiver.loadRelaxed()->objectName()),
method.methodSignature().constData()); method.methodSignature().constData());
c = c->nextConnectionList.load(); c = c->nextConnectionList.loadRelaxed();
} }
} }
} else { } else {
@ -4910,17 +4910,17 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s
QOrderedMutexLocker locker(signalSlotLock(sender), QOrderedMutexLocker locker(signalSlotLock(sender),
signalSlotLock(receiver)); signalSlotLock(receiver));
if (type & Qt::UniqueConnection && slot && QObjectPrivate::get(s)->connections.load()) { if (type & Qt::UniqueConnection && slot && QObjectPrivate::get(s)->connections.loadRelaxed()) {
QObjectPrivate::ConnectionData *connections = QObjectPrivate::get(s)->connections.load(); QObjectPrivate::ConnectionData *connections = QObjectPrivate::get(s)->connections.loadRelaxed();
if (connections->signalVectorCount() > signal_index) { if (connections->signalVectorCount() > signal_index) {
const QObjectPrivate::Connection *c2 = connections->signalVector.load()->at(signal_index).first.load(); const QObjectPrivate::Connection *c2 = connections->signalVector.loadRelaxed()->at(signal_index).first.loadRelaxed();
while (c2) { while (c2) {
if (c2->receiver.load() == receiver && c2->isSlotObject && c2->slotObj->compare(slot)) { if (c2->receiver.loadRelaxed() == receiver && c2->isSlotObject && c2->slotObj->compare(slot)) {
slotObj->destroyIfLastRef(); slotObj->destroyIfLastRef();
return QMetaObject::Connection(); return QMetaObject::Connection();
} }
c2 = c2->nextConnectionList.load(); c2 = c2->nextConnectionList.loadRelaxed();
} }
} }
type = static_cast<Qt::ConnectionType>(type ^ Qt::UniqueConnection); type = static_cast<Qt::ConnectionType>(type ^ Qt::UniqueConnection);
@ -4931,13 +4931,13 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s
c->signal_index = signal_index; c->signal_index = signal_index;
QThreadData *td = r->d_func()->threadData; QThreadData *td = r->d_func()->threadData;
td->ref(); td->ref();
c->receiverThreadData.store(td); c->receiverThreadData.storeRelaxed(td);
c->receiver.store(r); c->receiver.storeRelaxed(r);
c->slotObj = slotObj; c->slotObj = slotObj;
c->connectionType = type; c->connectionType = type;
c->isSlotObject = true; c->isSlotObject = true;
if (types) { if (types) {
c->argumentTypes.store(types); c->argumentTypes.storeRelaxed(types);
c->ownArgumentTypes = false; c->ownArgumentTypes = false;
} }
@ -4966,7 +4966,7 @@ bool QObject::disconnect(const QMetaObject::Connection &connection)
if (!c) if (!c)
return false; return false;
QObject *receiver = c->receiver.load(); QObject *receiver = c->receiver.loadRelaxed();
if (!receiver) if (!receiver)
return false; return false;
@ -4978,11 +4978,11 @@ bool QObject::disconnect(const QMetaObject::Connection &connection)
QOrderedMutexLocker locker(senderMutex, receiverMutex); QOrderedMutexLocker locker(senderMutex, receiverMutex);
// load receiver once again and recheck to ensure nobody else has removed the connection in the meantime // load receiver once again and recheck to ensure nobody else has removed the connection in the meantime
receiver = c->receiver.load(); receiver = c->receiver.loadRelaxed();
if (!receiver) if (!receiver)
return false; return false;
connections = QObjectPrivate::get(c->sender)->connections.load(); connections = QObjectPrivate::get(c->sender)->connections.loadRelaxed();
Q_ASSERT(connections); Q_ASSERT(connections);
connections->removeConnection(c); connections->removeConnection(c);
} }
@ -5174,7 +5174,7 @@ bool QMetaObject::Connection::isConnected_helper() const
Q_ASSERT(d_ptr); // we're only called from operator RestrictedBool() const Q_ASSERT(d_ptr); // we're only called from operator RestrictedBool() const
QObjectPrivate::Connection *c = static_cast<QObjectPrivate::Connection *>(d_ptr); QObjectPrivate::Connection *c = static_cast<QObjectPrivate::Connection *>(d_ptr);
return c->receiver.load(); return c->receiver.loadRelaxed();
} }

View File

@ -184,7 +184,7 @@ public:
} }
void deref() { void deref() {
if (!ref_.deref()) { if (!ref_.deref()) {
Q_ASSERT(!receiver.load()); Q_ASSERT(!receiver.loadRelaxed());
Q_ASSERT(!isSlotObject); Q_ASSERT(!isSlotObject);
delete this; delete this;
} }
@ -202,7 +202,7 @@ public:
: receiver(receiver), sender(sender), signal(signal) : receiver(receiver), sender(sender), signal(signal)
{ {
if (receiver) { if (receiver) {
ConnectionData *cd = receiver->d_func()->connections.load(); ConnectionData *cd = receiver->d_func()->connections.loadRelaxed();
previous = cd->currentSender; previous = cd->currentSender;
cd->currentSender = this; cd->currentSender = this;
} }
@ -210,7 +210,7 @@ public:
~Sender() ~Sender()
{ {
if (receiver) if (receiver)
receiver->d_func()->connections.load()->currentSender = previous; receiver->d_func()->connections.loadRelaxed()->currentSender = previous;
} }
void receiverDeleted() void receiverDeleted()
{ {
@ -268,8 +268,8 @@ public:
~ConnectionData() ~ConnectionData()
{ {
deleteOrphaned(orphaned.load()); deleteOrphaned(orphaned.loadRelaxed());
SignalVector *v = signalVector.load(); SignalVector *v = signalVector.loadRelaxed();
if (v) if (v)
free(v); free(v);
} }
@ -279,18 +279,18 @@ public:
void removeConnection(Connection *c); void removeConnection(Connection *c);
void cleanOrphanedConnections(QObject *sender) void cleanOrphanedConnections(QObject *sender)
{ {
if (orphaned.load() && ref == 1) if (orphaned.loadRelaxed() && ref == 1)
cleanOrphanedConnectionsImpl(sender); cleanOrphanedConnectionsImpl(sender);
} }
void cleanOrphanedConnectionsImpl(QObject *sender); void cleanOrphanedConnectionsImpl(QObject *sender);
ConnectionList &connectionsForSignal(int signal) ConnectionList &connectionsForSignal(int signal)
{ {
return signalVector.load()->at(signal); return signalVector.loadRelaxed()->at(signal);
} }
void resizeSignalVector(uint size) { void resizeSignalVector(uint size) {
SignalVector *vector = this->signalVector.load(); SignalVector *vector = this->signalVector.loadRelaxed();
if (vector && vector->allocated > size) if (vector && vector->allocated > size)
return; return;
size = (size + 7) & ~7; size = (size + 7) & ~7;
@ -305,14 +305,14 @@ public:
newVector->next = nullptr; newVector->next = nullptr;
newVector->allocated = size; newVector->allocated = size;
signalVector.store(newVector); signalVector.storeRelaxed(newVector);
if (vector) { if (vector) {
vector->nextInOrphanList = orphaned.load(); vector->nextInOrphanList = orphaned.loadRelaxed();
orphaned.store(ConnectionOrSignalVector::fromSignalVector(vector)); orphaned.storeRelaxed(ConnectionOrSignalVector::fromSignalVector(vector));
} }
} }
int signalVectorCount() const { int signalVectorCount() const {
return signalVector ? signalVector.load()->count() : -1; return signalVector ? signalVector.loadRelaxed()->count() : -1;
} }
static void deleteOrphaned(ConnectionOrSignalVector *c); static void deleteOrphaned(ConnectionOrSignalVector *c);
@ -366,11 +366,11 @@ public:
void ensureConnectionData() void ensureConnectionData()
{ {
if (connections.load()) if (connections.loadRelaxed())
return; return;
ConnectionData *cd = new ConnectionData; ConnectionData *cd = new ConnectionData;
cd->ref.ref(); cd->ref.ref();
connections.store(cd); connections.storeRelaxed(cd);
} }
public: public:
ExtraData *extraData; // extra data set by the user ExtraData *extraData; // extra data set by the user

View File

@ -152,7 +152,7 @@ QSocketNotifier::QSocketNotifier(qintptr socket, Type type, QObject *parent)
else if (!d->threadData->hasEventDispatcher()) else if (!d->threadData->hasEventDispatcher())
qWarning("QSocketNotifier: Can only be used with threads started with QThread"); qWarning("QSocketNotifier: Can only be used with threads started with QThread");
else else
d->threadData->eventDispatcher.load()->registerSocketNotifier(this); d->threadData->eventDispatcher.loadRelaxed()->registerSocketNotifier(this);
} }
/*! /*!
@ -241,9 +241,9 @@ void QSocketNotifier::setEnabled(bool enable)
return; return;
} }
if (d->snenabled) if (d->snenabled)
d->threadData->eventDispatcher.load()->registerSocketNotifier(this); d->threadData->eventDispatcher.loadRelaxed()->registerSocketNotifier(this);
else else
d->threadData->eventDispatcher.load()->unregisterSocketNotifier(this); d->threadData->eventDispatcher.loadRelaxed()->unregisterSocketNotifier(this);
} }

View File

@ -2366,7 +2366,7 @@ QVariant& QVariant::operator=(const QVariant &variant)
void QVariant::detach() void QVariant::detach()
{ {
if (!d.is_shared || d.data.shared->ref.load() == 1) if (!d.is_shared || d.data.shared->ref.loadRelaxed() == 1)
return; return;
Private dd; Private dd;

View File

@ -577,7 +577,7 @@ Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant::Type p);
#endif #endif
inline bool QVariant::isDetached() const inline bool QVariant::isDetached() const
{ return !d.is_shared || d.data.shared->ref.load() == 1; } { return !d.is_shared || d.data.shared->ref.loadRelaxed() == 1; }
#ifdef Q_QDOC #ifdef Q_QDOC

View File

@ -124,7 +124,7 @@ QWinEventNotifier::QWinEventNotifier(HANDLE hEvent, QObject *parent)
: QObject(*new QWinEventNotifierPrivate(hEvent, false), parent) : QObject(*new QWinEventNotifierPrivate(hEvent, false), parent)
{ {
Q_D(QWinEventNotifier); Q_D(QWinEventNotifier);
QAbstractEventDispatcher *eventDispatcher = d->threadData->eventDispatcher.load(); QAbstractEventDispatcher *eventDispatcher = d->threadData->eventDispatcher.loadRelaxed();
if (Q_UNLIKELY(!eventDispatcher)) { if (Q_UNLIKELY(!eventDispatcher)) {
qWarning("QWinEventNotifier: Can only be used with threads started with QThread"); qWarning("QWinEventNotifier: Can only be used with threads started with QThread");
return; return;
@ -197,7 +197,7 @@ void QWinEventNotifier::setEnabled(bool enable)
return; return;
d->enabled = enable; d->enabled = enable;
QAbstractEventDispatcher *eventDispatcher = d->threadData->eventDispatcher.load(); QAbstractEventDispatcher *eventDispatcher = d->threadData->eventDispatcher.loadRelaxed();
if (!eventDispatcher) { // perhaps application is shutting down if (!eventDispatcher) { // perhaps application is shutting down
if (!enable && d->waitHandle != nullptr) if (!enable && d->waitHandle != nullptr)
d->unregisterWaitObject(); d->unregisterWaitObject();
@ -256,7 +256,7 @@ void QWinEventNotifierPrivate::unregisterWaitObject()
static void CALLBACK wfsoCallback(void *context, BOOLEAN /*ignore*/) static void CALLBACK wfsoCallback(void *context, BOOLEAN /*ignore*/)
{ {
QWinEventNotifierPrivate *nd = reinterpret_cast<QWinEventNotifierPrivate *>(context); QWinEventNotifierPrivate *nd = reinterpret_cast<QWinEventNotifierPrivate *>(context);
QAbstractEventDispatcher *eventDispatcher = nd->threadData->eventDispatcher.load(); QAbstractEventDispatcher *eventDispatcher = nd->threadData->eventDispatcher.loadRelaxed();
// Happens when Q(Core)Application is destroyed before QWinEventNotifier. // Happens when Q(Core)Application is destroyed before QWinEventNotifier.
// https://bugreports.qt.io/browse/QTBUG-70214 // https://bugreports.qt.io/browse/QTBUG-70214

View File

@ -405,10 +405,10 @@ inline void QLibraryStore::cleanup()
LibraryMap::Iterator it = data->libraryMap.begin(); LibraryMap::Iterator it = data->libraryMap.begin();
for (; it != data->libraryMap.end(); ++it) { for (; it != data->libraryMap.end(); ++it) {
QLibraryPrivate *lib = it.value(); QLibraryPrivate *lib = it.value();
if (lib->libraryRefCount.load() == 1) { if (lib->libraryRefCount.loadRelaxed() == 1) {
if (lib->libraryUnloadCount.load() > 0) { if (lib->libraryUnloadCount.loadRelaxed() > 0) {
Q_ASSERT(lib->pHnd); Q_ASSERT(lib->pHnd);
lib->libraryUnloadCount.store(1); lib->libraryUnloadCount.storeRelaxed(1);
#ifdef __GLIBC__ #ifdef __GLIBC__
// glibc has a bug in unloading from global destructors // glibc has a bug in unloading from global destructors
// see https://bugzilla.novell.com/show_bug.cgi?id=622977 // see https://bugzilla.novell.com/show_bug.cgi?id=622977
@ -428,7 +428,7 @@ inline void QLibraryStore::cleanup()
for (QLibraryPrivate *lib : qAsConst(data->libraryMap)) { for (QLibraryPrivate *lib : qAsConst(data->libraryMap)) {
if (lib) if (lib)
qDebug() << "On QtCore unload," << lib->fileName << "was leaked, with" qDebug() << "On QtCore unload," << lib->fileName << "was leaked, with"
<< lib->libraryRefCount.load() << "users"; << lib->libraryRefCount.loadRelaxed() << "users";
} }
} }
@ -487,7 +487,7 @@ inline void QLibraryStore::releaseLibrary(QLibraryPrivate *lib)
} }
// no one else is using // no one else is using
Q_ASSERT(lib->libraryUnloadCount.load() == 0); Q_ASSERT(lib->libraryUnloadCount.loadRelaxed() == 0);
if (Q_LIKELY(data) && !lib->fileName.isEmpty()) { if (Q_LIKELY(data) && !lib->fileName.isEmpty()) {
QLibraryPrivate *that = data->libraryMap.take(lib->fileName); QLibraryPrivate *that = data->libraryMap.take(lib->fileName);
@ -501,7 +501,7 @@ QLibraryPrivate::QLibraryPrivate(const QString &canonicalFileName, const QString
: pHnd(0), fileName(canonicalFileName), fullVersion(version), instance(0), : pHnd(0), fileName(canonicalFileName), fullVersion(version), instance(0),
libraryRefCount(0), libraryUnloadCount(0), pluginState(MightBeAPlugin) libraryRefCount(0), libraryUnloadCount(0), pluginState(MightBeAPlugin)
{ {
loadHintsInt.store(loadHints); loadHintsInt.storeRelaxed(loadHints);
if (canonicalFileName.isEmpty()) if (canonicalFileName.isEmpty())
errorString = QLibrary::tr("The shared library was not found."); errorString = QLibrary::tr("The shared library was not found.");
} }
@ -522,7 +522,7 @@ void QLibraryPrivate::mergeLoadHints(QLibrary::LoadHints lh)
if (pHnd) if (pHnd)
return; return;
loadHintsInt.store(lh); loadHintsInt.storeRelaxed(lh);
} }
QFunctionPointer QLibraryPrivate::resolve(const char *symbol) QFunctionPointer QLibraryPrivate::resolve(const char *symbol)
@ -575,7 +575,7 @@ bool QLibraryPrivate::unload(UnloadFlag flag)
{ {
if (!pHnd) if (!pHnd)
return false; return false;
if (libraryUnloadCount.load() > 0 && !libraryUnloadCount.deref()) { // only unload if ALL QLibrary instance wanted to if (libraryUnloadCount.loadRelaxed() > 0 && !libraryUnloadCount.deref()) { // only unload if ALL QLibrary instance wanted to
delete inst.data(); delete inst.data();
if (flag == NoUnloadSys || unload_sys()) { if (flag == NoUnloadSys || unload_sys()) {
if (qt_debug_component()) if (qt_debug_component())

View File

@ -92,7 +92,7 @@ public:
QFunctionPointer resolve(const char *); QFunctionPointer resolve(const char *);
QLibrary::LoadHints loadHints() const QLibrary::LoadHints loadHints() const
{ return QLibrary::LoadHints(loadHintsInt.load()); } { return QLibrary::LoadHints(loadHintsInt.loadRelaxed()); }
void setLoadHints(QLibrary::LoadHints lh); void setLoadHints(QLibrary::LoadHints lh);
static QLibraryPrivate *findOrCreate(const QString &fileName, const QString &version = QString(), static QLibraryPrivate *findOrCreate(const QString &fileName, const QString &version = QString(),

View File

@ -849,7 +849,7 @@ QCborContainerPrivate *QCborContainerPrivate::clone(QCborContainerPrivate *d, qs
QCborContainerPrivate *QCborContainerPrivate::detach(QCborContainerPrivate *d, qsizetype reserved) QCborContainerPrivate *QCborContainerPrivate::detach(QCborContainerPrivate *d, qsizetype reserved)
{ {
if (!d || d->ref.load() != 1) if (!d || d->ref.loadRelaxed() != 1)
return clone(d, reserved); return clone(d, reserved);
return d; return d;
} }
@ -884,12 +884,12 @@ void QCborContainerPrivate::replaceAt_complex(Element &e, const QCborValue &valu
// detect self-assignment // detect self-assignment
if (Q_UNLIKELY(this == value.container)) { if (Q_UNLIKELY(this == value.container)) {
Q_ASSERT(ref.load() >= 2); Q_ASSERT(ref.loadRelaxed() >= 2);
if (disp == MoveContainer) if (disp == MoveContainer)
ref.deref(); // not deref() because it can't drop to 0 ref.deref(); // not deref() because it can't drop to 0
QCborContainerPrivate *d = QCborContainerPrivate::clone(this); QCborContainerPrivate *d = QCborContainerPrivate::clone(this);
d->elements.detach(); d->elements.detach();
d->ref.store(1); d->ref.storeRelaxed(1);
e.container = d; e.container = d;
} else { } else {
e.container = value.container; e.container = value.container;
@ -1368,7 +1368,7 @@ static Element decodeBasicValueFromCbor(QCborStreamReader &reader)
static inline QCborContainerPrivate *createContainerFromCbor(QCborStreamReader &reader) static inline QCborContainerPrivate *createContainerFromCbor(QCborStreamReader &reader)
{ {
auto d = new QCborContainerPrivate; auto d = new QCborContainerPrivate;
d->ref.store(1); d->ref.storeRelaxed(1);
d->decodeFromCbor(reader); d->decodeFromCbor(reader);
return d; return d;
} }
@ -1643,7 +1643,7 @@ QCborValue::QCborValue(const QByteArray &ba)
: n(0), container(new QCborContainerPrivate), t(ByteArray) : n(0), container(new QCborContainerPrivate), t(ByteArray)
{ {
container->appendByteData(ba.constData(), ba.size(), t); container->appendByteData(ba.constData(), ba.size(), t);
container->ref.store(1); container->ref.storeRelaxed(1);
} }
/*! /*!
@ -1656,7 +1656,7 @@ QCborValue::QCborValue(const QString &s)
: n(0), container(new QCborContainerPrivate), t(String) : n(0), container(new QCborContainerPrivate), t(String)
{ {
container->append(s); container->append(s);
container->ref.store(1); container->ref.storeRelaxed(1);
} }
/*! /*!
@ -1671,7 +1671,7 @@ QCborValue::QCborValue(QLatin1String s)
: n(0), container(new QCborContainerPrivate), t(String) : n(0), container(new QCborContainerPrivate), t(String)
{ {
container->append(s); container->append(s);
container->ref.store(1); container->ref.storeRelaxed(1);
} }
/*! /*!
@ -1719,7 +1719,7 @@ QCborValue::QCborValue(const QCborMap &m)
QCborValue::QCborValue(QCborTag t, const QCborValue &tv) QCborValue::QCborValue(QCborTag t, const QCborValue &tv)
: n(-1), container(new QCborContainerPrivate), t(Tag) : n(-1), container(new QCborContainerPrivate), t(Tag)
{ {
container->ref.store(1); container->ref.storeRelaxed(1);
container->append(t); container->append(t);
container->append(tv); container->append(tv);
} }

View File

@ -719,7 +719,7 @@ public:
Data *clone(Base *b, int reserve = 0) Data *clone(Base *b, int reserve = 0)
{ {
int size = sizeof(Header) + b->size; int size = sizeof(Header) + b->size;
if (b == header->root() && ref.load() == 1 && alloc >= size + reserve) if (b == header->root() && ref.loadRelaxed() == 1 && alloc >= size + reserve)
return this; return this;
if (reserve) { if (reserve) {

View File

@ -1226,7 +1226,7 @@ bool QJsonArray::detach2(uint reserve)
d->ref.ref(); d->ref.ref();
return true; return true;
} }
if (reserve == 0 && d->ref.load() == 1) if (reserve == 0 && d->ref.loadRelaxed() == 1)
return true; return true;
QJsonPrivate::Data *x = d->clone(a, reserve); QJsonPrivate::Data *x = d->clone(a, reserve);

View File

@ -646,7 +646,7 @@ bool QJsonObject::operator!=(const QJsonObject &other) const
*/ */
QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it) QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it)
{ {
Q_ASSERT(d && d->ref.load() == 1); Q_ASSERT(d && d->ref.loadRelaxed() == 1);
if (it.o != this || it.i < 0 || it.i >= (int)o->length) if (it.o != this || it.i < 0 || it.i >= (int)o->length)
return iterator(this, o->length); return iterator(this, o->length);
@ -1231,7 +1231,7 @@ bool QJsonObject::detach2(uint reserve)
d->ref.ref(); d->ref.ref();
return true; return true;
} }
if (reserve == 0 && d->ref.load() == 1) if (reserve == 0 && d->ref.loadRelaxed() == 1)
return true; return true;
QJsonPrivate::Data *x = d->clone(o, reserve); QJsonPrivate::Data *x = d->clone(o, reserve);

View File

@ -257,7 +257,7 @@ inline void qAtomicAssign(T *&d, T *x)
template <typename T> template <typename T>
inline void qAtomicDetach(T *&d) inline void qAtomicDetach(T *&d)
{ {
if (d->ref.load() == 1) if (d->ref.loadRelaxed() == 1)
return; return;
T *x = d; T *x = d;
d = new T(*d); d = new T(*d);

View File

@ -97,7 +97,7 @@ static inline int switch_off(QAtomicInt &a, int which)
static inline int switch_from_to(QAtomicInt &a, int from, int to) static inline int switch_from_to(QAtomicInt &a, int from, int to)
{ {
int newValue; int newValue;
int expected = a.load(); int expected = a.loadRelaxed();
do { do {
newValue = (expected & ~from) | to; newValue = (expected & ~from) | to;
} while (!a.testAndSetRelaxed(expected, newValue, expected)); } while (!a.testAndSetRelaxed(expected, newValue, expected));
@ -107,7 +107,7 @@ static inline int switch_from_to(QAtomicInt &a, int from, int to)
void QFutureInterfaceBase::cancel() void QFutureInterfaceBase::cancel()
{ {
QMutexLocker locker(&d->m_mutex); QMutexLocker locker(&d->m_mutex);
if (d->state.load() & Canceled) if (d->state.loadRelaxed() & Canceled)
return; return;
switch_from_to(d->state, Paused, Canceled); switch_from_to(d->state, Paused, Canceled);
@ -132,7 +132,7 @@ void QFutureInterfaceBase::setPaused(bool paused)
void QFutureInterfaceBase::togglePaused() void QFutureInterfaceBase::togglePaused()
{ {
QMutexLocker locker(&d->m_mutex); QMutexLocker locker(&d->m_mutex);
if (d->state.load() & Paused) { if (d->state.loadRelaxed() & Paused) {
switch_off(d->state, Paused); switch_off(d->state, Paused);
d->pausedWaitCondition.wakeAll(); d->pausedWaitCondition.wakeAll();
d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed)); d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed));
@ -149,7 +149,7 @@ void QFutureInterfaceBase::setThrottled(bool enable)
switch_on(d->state, Throttled); switch_on(d->state, Throttled);
} else { } else {
switch_off(d->state, Throttled); switch_off(d->state, Throttled);
if (!(d->state.load() & Paused)) if (!(d->state.loadRelaxed() & Paused))
d->pausedWaitCondition.wakeAll(); d->pausedWaitCondition.wakeAll();
} }
} }
@ -201,13 +201,13 @@ void QFutureInterfaceBase::waitForResume()
{ {
// return early if possible to avoid taking the mutex lock. // return early if possible to avoid taking the mutex lock.
{ {
const int state = d->state.load(); const int state = d->state.loadRelaxed();
if (!(state & Paused) || (state & Canceled)) if (!(state & Paused) || (state & Canceled))
return; return;
} }
QMutexLocker lock(&d->m_mutex); QMutexLocker lock(&d->m_mutex);
const int state = d->state.load(); const int state = d->state.loadRelaxed();
if (!(state & Paused) || (state & Canceled)) if (!(state & Paused) || (state & Canceled))
return; return;
@ -256,7 +256,7 @@ bool QFutureInterfaceBase::isProgressUpdateNeeded() const
void QFutureInterfaceBase::reportStarted() void QFutureInterfaceBase::reportStarted()
{ {
QMutexLocker locker(&d->m_mutex); QMutexLocker locker(&d->m_mutex);
if (d->state.load() & (Started|Canceled|Finished)) if (d->state.loadRelaxed() & (Started|Canceled|Finished))
return; return;
d->setState(State(Started | Running)); d->setState(State(Started | Running));
@ -272,7 +272,7 @@ void QFutureInterfaceBase::reportCanceled()
void QFutureInterfaceBase::reportException(const QException &exception) void QFutureInterfaceBase::reportException(const QException &exception)
{ {
QMutexLocker locker(&d->m_mutex); QMutexLocker locker(&d->m_mutex);
if (d->state.load() & (Canceled|Finished)) if (d->state.loadRelaxed() & (Canceled|Finished))
return; return;
d->m_exceptionStore.setException(exception); d->m_exceptionStore.setException(exception);
@ -307,7 +307,7 @@ int QFutureInterfaceBase::expectedResultCount()
bool QFutureInterfaceBase::queryState(State state) const bool QFutureInterfaceBase::queryState(State state) const
{ {
return d->state.load() & state; return d->state.loadRelaxed() & state;
} }
void QFutureInterfaceBase::waitForResult(int resultIndex) void QFutureInterfaceBase::waitForResult(int resultIndex)
@ -352,7 +352,7 @@ void QFutureInterfaceBase::waitForFinished()
void QFutureInterfaceBase::reportResultsReady(int beginIndex, int endIndex) void QFutureInterfaceBase::reportResultsReady(int beginIndex, int endIndex)
{ {
if (beginIndex == endIndex || (d->state.load() & (Canceled|Finished))) if (beginIndex == endIndex || (d->state.loadRelaxed() & (Canceled|Finished)))
return; return;
d->waitCondition.wakeAll(); d->waitCondition.wakeAll();
@ -414,7 +414,7 @@ void QFutureInterfaceBase::setProgressValueAndText(int progressValue,
if (d->m_progressValue >= progressValue) if (d->m_progressValue >= progressValue)
return; return;
if (d->state.load() & (Canceled|Finished)) if (d->state.loadRelaxed() & (Canceled|Finished))
return; return;
if (d->internal_updateProgress(progressValue, progressText)) { if (d->internal_updateProgress(progressValue, progressText)) {
@ -486,10 +486,10 @@ bool QFutureInterfaceBasePrivate::internal_waitForNextResult()
if (m_results.hasNextResult()) if (m_results.hasNextResult())
return true; return true;
while ((state.load() & QFutureInterfaceBase::Running) && m_results.hasNextResult() == false) while ((state.loadRelaxed() & QFutureInterfaceBase::Running) && m_results.hasNextResult() == false)
waitCondition.wait(&m_mutex); waitCondition.wait(&m_mutex);
return !(state.load() & QFutureInterfaceBase::Canceled) && m_results.hasNextResult(); return !(state.loadRelaxed() & QFutureInterfaceBase::Canceled) && m_results.hasNextResult();
} }
bool QFutureInterfaceBasePrivate::internal_updateProgress(int progress, bool QFutureInterfaceBasePrivate::internal_updateProgress(int progress,
@ -512,8 +512,8 @@ bool QFutureInterfaceBasePrivate::internal_updateProgress(int progress,
void QFutureInterfaceBasePrivate::internal_setThrottled(bool enable) void QFutureInterfaceBasePrivate::internal_setThrottled(bool enable)
{ {
// bail out if we are not changing the state // bail out if we are not changing the state
if ((enable && (state.load() & QFutureInterfaceBase::Throttled)) if ((enable && (state.loadRelaxed() & QFutureInterfaceBase::Throttled))
|| (!enable && !(state.load() & QFutureInterfaceBase::Throttled))) || (!enable && !(state.loadRelaxed() & QFutureInterfaceBase::Throttled)))
return; return;
// change the state // change the state
@ -521,7 +521,7 @@ void QFutureInterfaceBasePrivate::internal_setThrottled(bool enable)
switch_on(state, QFutureInterfaceBase::Throttled); switch_on(state, QFutureInterfaceBase::Throttled);
} else { } else {
switch_off(state, QFutureInterfaceBase::Throttled); switch_off(state, QFutureInterfaceBase::Throttled);
if (!(state.load() & QFutureInterfaceBase::Paused)) if (!(state.loadRelaxed() & QFutureInterfaceBase::Paused))
pausedWaitCondition.wakeAll(); pausedWaitCondition.wakeAll();
} }
} }
@ -556,7 +556,7 @@ void QFutureInterfaceBasePrivate::connectOutputInterface(QFutureCallOutInterface
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
if (state.load() & QFutureInterfaceBase::Started) { if (state.loadRelaxed() & QFutureInterfaceBase::Started) {
interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Started)); interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Started));
interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::ProgressRange, interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::ProgressRange,
m_progressMinimum, m_progressMinimum,
@ -576,13 +576,13 @@ void QFutureInterfaceBasePrivate::connectOutputInterface(QFutureCallOutInterface
it.batchedAdvance(); it.batchedAdvance();
} }
if (state.load() & QFutureInterfaceBase::Paused) if (state.loadRelaxed() & QFutureInterfaceBase::Paused)
interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Paused));
if (state.load() & QFutureInterfaceBase::Canceled) if (state.loadRelaxed() & QFutureInterfaceBase::Canceled)
interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Canceled));
if (state.load() & QFutureInterfaceBase::Finished) if (state.loadRelaxed() & QFutureInterfaceBase::Finished)
interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Finished)); interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Finished));
outputConnections.append(interface); outputConnections.append(interface);
@ -601,7 +601,7 @@ void QFutureInterfaceBasePrivate::disconnectOutputInterface(QFutureCallOutInterf
void QFutureInterfaceBasePrivate::setState(QFutureInterfaceBase::State newState) void QFutureInterfaceBasePrivate::setState(QFutureInterfaceBase::State newState)
{ {
state.store(newState); state.storeRelaxed(newState);
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -144,11 +144,11 @@ public:
// Default ref counter for QFIBP // Default ref counter for QFIBP
inline bool ref() { return m_refCount.ref(); } inline bool ref() { return m_refCount.ref(); }
inline bool deref() { return m_refCount.deref(); } inline bool deref() { return m_refCount.deref(); }
inline int load() const { return m_refCount.load(); } inline int load() const { return m_refCount.loadRelaxed(); }
// Ref counter for type T // Ref counter for type T
inline bool refT() { return m_refCountT.ref(); } inline bool refT() { return m_refCountT.ref(); }
inline bool derefT() { return m_refCountT.deref(); } inline bool derefT() { return m_refCountT.deref(); }
inline int loadT() const { return m_refCountT.load(); } inline int loadT() const { return m_refCountT.loadRelaxed(); }
private: private:
QAtomicInt m_refCount; QAtomicInt m_refCount;

View File

@ -402,7 +402,7 @@ void QFutureWatcherBase::disconnectOutputInterface(bool pendingAssignment)
{ {
if (pendingAssignment) { if (pendingAssignment) {
Q_D(QFutureWatcherBase); Q_D(QFutureWatcherBase);
d->pendingResultsReady.store(0); d->pendingResultsReady.storeRelaxed(0);
qDeleteAll(d->pendingCallOutEvents); qDeleteAll(d->pendingCallOutEvents);
d->pendingCallOutEvents.clear(); d->pendingCallOutEvents.clear();
d->finished = false; /* May soon be amended, during connectOutputInterface() */ d->finished = false; /* May soon be amended, during connectOutputInterface() */
@ -441,7 +441,7 @@ void QFutureWatcherBasePrivate::sendCallOutEvent(QFutureCallOutEvent *event)
emit q->finished(); emit q->finished();
break; break;
case QFutureCallOutEvent::Canceled: case QFutureCallOutEvent::Canceled:
pendingResultsReady.store(0); pendingResultsReady.storeRelaxed(0);
emit q->canceled(); emit q->canceled();
break; break;
case QFutureCallOutEvent::Paused: case QFutureCallOutEvent::Paused:
@ -466,7 +466,7 @@ void QFutureWatcherBasePrivate::sendCallOutEvent(QFutureCallOutEvent *event)
emit q->resultsReadyAt(beginIndex, endIndex); emit q->resultsReadyAt(beginIndex, endIndex);
if (resultAtConnected.load() <= 0) if (resultAtConnected.loadRelaxed() <= 0)
break; break;
for (int i = beginIndex; i < endIndex; ++i) for (int i = beginIndex; i < endIndex; ++i)

View File

@ -179,7 +179,7 @@ public:
*/ */
QMutex::QMutex(RecursionMode mode) QMutex::QMutex(RecursionMode mode)
{ {
d_ptr.store(mode == Recursive ? new QRecursiveMutexPrivate : 0); d_ptr.storeRelaxed(mode == Recursive ? new QRecursiveMutexPrivate : 0);
} }
/*! /*!
@ -189,12 +189,12 @@ QMutex::QMutex(RecursionMode mode)
*/ */
QMutex::~QMutex() QMutex::~QMutex()
{ {
QMutexData *d = d_ptr.load(); QMutexData *d = d_ptr.loadRelaxed();
if (isRecursive()) { if (isRecursive()) {
delete static_cast<QRecursiveMutexPrivate *>(d); delete static_cast<QRecursiveMutexPrivate *>(d);
} else if (d) { } else if (d) {
#ifndef QT_LINUX_FUTEX #ifndef QT_LINUX_FUTEX
if (d != dummyLocked() && static_cast<QMutexPrivate *>(d)->possiblyUnlocked.load() if (d != dummyLocked() && static_cast<QMutexPrivate *>(d)->possiblyUnlocked.loadRelaxed()
&& tryLock()) { && tryLock()) {
unlock(); unlock();
return; return;
@ -517,7 +517,7 @@ bool QBasicMutex::lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT
} }
QMutexPrivate *d = static_cast<QMutexPrivate *>(copy); QMutexPrivate *d = static_cast<QMutexPrivate *>(copy);
if (timeout == 0 && !d->possiblyUnlocked.load()) if (timeout == 0 && !d->possiblyUnlocked.loadRelaxed())
return false; return false;
// At this point we have a pointer to a QMutexPrivate. But the other thread // At this point we have a pointer to a QMutexPrivate. But the other thread
@ -541,7 +541,7 @@ bool QBasicMutex::lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT
// is set to the BigNumber magic value set in unlockInternal() // is set to the BigNumber magic value set in unlockInternal()
int old_waiters; int old_waiters;
do { do {
old_waiters = d->waiters.load(); old_waiters = d->waiters.loadRelaxed();
if (old_waiters == -QMutexPrivate::BigNumber) { if (old_waiters == -QMutexPrivate::BigNumber) {
// we are unlocking, and the thread that unlocks is about to change d to 0 // we are unlocking, and the thread that unlocks is about to change d to 0
// we try to acquire the mutex by changing to dummyLocked() // we try to acquire the mutex by changing to dummyLocked()
@ -550,7 +550,7 @@ bool QBasicMutex::lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT
d->deref(); d->deref();
return true; return true;
} else { } else {
Q_ASSERT(d != d_ptr.load()); //else testAndSetAcquire should have succeeded Q_ASSERT(d != d_ptr.loadRelaxed()); //else testAndSetAcquire should have succeeded
// Mutex is likely to bo 0, we should continue the outer-loop, // Mutex is likely to bo 0, we should continue the outer-loop,
// set old_waiters to the magic value of BigNumber // set old_waiters to the magic value of BigNumber
old_waiters = QMutexPrivate::BigNumber; old_waiters = QMutexPrivate::BigNumber;
@ -563,7 +563,7 @@ bool QBasicMutex::lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT
// The mutex was unlocked before we incremented waiters. // The mutex was unlocked before we incremented waiters.
if (old_waiters != QMutexPrivate::BigNumber) { if (old_waiters != QMutexPrivate::BigNumber) {
//we did not break the previous loop //we did not break the previous loop
Q_ASSERT(d->waiters.load() >= 1); Q_ASSERT(d->waiters.loadRelaxed() >= 1);
d->waiters.deref(); d->waiters.deref();
} }
d->deref(); d->deref();
@ -572,11 +572,11 @@ bool QBasicMutex::lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT
if (d->wait(timeout)) { if (d->wait(timeout)) {
// reset the possiblyUnlocked flag if needed (and deref its corresponding reference) // reset the possiblyUnlocked flag if needed (and deref its corresponding reference)
if (d->possiblyUnlocked.load() && d->possiblyUnlocked.testAndSetRelaxed(true, false)) if (d->possiblyUnlocked.loadRelaxed() && d->possiblyUnlocked.testAndSetRelaxed(true, false))
d->deref(); d->deref();
d->derefWaiters(1); d->derefWaiters(1);
//we got the lock. (do not deref) //we got the lock. (do not deref)
Q_ASSERT(d == d_ptr.load()); Q_ASSERT(d == d_ptr.loadRelaxed());
return true; return true;
} else { } else {
Q_ASSERT(timeout >= 0); Q_ASSERT(timeout >= 0);
@ -593,7 +593,7 @@ bool QBasicMutex::lockInternal(int timeout) QT_MUTEX_LOCK_NOEXCEPT
return false; return false;
} }
} }
Q_ASSERT(d_ptr.load() != 0); Q_ASSERT(d_ptr.loadRelaxed() != 0);
return true; return true;
} }
@ -618,7 +618,7 @@ void QBasicMutex::unlockInternal() noexcept
//there is no one waiting on this mutex anymore, set the mutex as unlocked (d = 0) //there is no one waiting on this mutex anymore, set the mutex as unlocked (d = 0)
if (d_ptr.testAndSetRelease(d, 0)) { if (d_ptr.testAndSetRelease(d, 0)) {
// reset the possiblyUnlocked flag if needed (and deref its corresponding reference) // reset the possiblyUnlocked flag if needed (and deref its corresponding reference)
if (d->possiblyUnlocked.load() && d->possiblyUnlocked.testAndSetRelaxed(true, false)) if (d->possiblyUnlocked.loadRelaxed() && d->possiblyUnlocked.testAndSetRelaxed(true, false))
d->deref(); d->deref();
} }
d->derefWaiters(0); d->derefWaiters(0);
@ -657,20 +657,20 @@ QMutexPrivate *QMutexPrivate::allocate()
int i = freelist()->next(); int i = freelist()->next();
QMutexPrivate *d = &(*freelist())[i]; QMutexPrivate *d = &(*freelist())[i];
d->id = i; d->id = i;
Q_ASSERT(d->refCount.load() == 0); Q_ASSERT(d->refCount.loadRelaxed() == 0);
Q_ASSERT(!d->recursive); Q_ASSERT(!d->recursive);
Q_ASSERT(!d->possiblyUnlocked.load()); Q_ASSERT(!d->possiblyUnlocked.loadRelaxed());
Q_ASSERT(d->waiters.load() == 0); Q_ASSERT(d->waiters.loadRelaxed() == 0);
d->refCount.store(1); d->refCount.storeRelaxed(1);
return d; return d;
} }
void QMutexPrivate::release() void QMutexPrivate::release()
{ {
Q_ASSERT(!recursive); Q_ASSERT(!recursive);
Q_ASSERT(refCount.load() == 0); Q_ASSERT(refCount.loadRelaxed() == 0);
Q_ASSERT(!possiblyUnlocked.load()); Q_ASSERT(!possiblyUnlocked.loadRelaxed());
Q_ASSERT(waiters.load() == 0); Q_ASSERT(waiters.loadRelaxed() == 0);
freelist()->release(id); freelist()->release(id);
} }
@ -680,7 +680,7 @@ void QMutexPrivate::derefWaiters(int value) noexcept
int old_waiters; int old_waiters;
int new_waiters; int new_waiters;
do { do {
old_waiters = waiters.load(); old_waiters = waiters.loadRelaxed();
new_waiters = old_waiters; new_waiters = old_waiters;
if (new_waiters < 0) { if (new_waiters < 0) {
new_waiters += QMutexPrivate::BigNumber; new_waiters += QMutexPrivate::BigNumber;
@ -696,7 +696,7 @@ void QMutexPrivate::derefWaiters(int value) noexcept
inline bool QRecursiveMutexPrivate::lock(int timeout) QT_MUTEX_LOCK_NOEXCEPT inline bool QRecursiveMutexPrivate::lock(int timeout) QT_MUTEX_LOCK_NOEXCEPT
{ {
Qt::HANDLE self = QThread::currentThreadId(); Qt::HANDLE self = QThread::currentThreadId();
if (owner.load() == self) { if (owner.loadRelaxed() == self) {
++count; ++count;
Q_ASSERT_X(count != 0, "QMutex::lock", "Overflow in recursion counter"); Q_ASSERT_X(count != 0, "QMutex::lock", "Overflow in recursion counter");
return true; return true;
@ -709,7 +709,7 @@ inline bool QRecursiveMutexPrivate::lock(int timeout) QT_MUTEX_LOCK_NOEXCEPT
} }
if (success) if (success)
owner.store(self); owner.storeRelaxed(self);
return success; return success;
} }
@ -721,7 +721,7 @@ inline void QRecursiveMutexPrivate::unlock() noexcept
if (count > 0) { if (count > 0) {
count--; count--;
} else { } else {
owner.store(0); owner.storeRelaxed(0);
mutex.QBasicMutex::unlock(); mutex.QBasicMutex::unlock();
} }
} }

View File

@ -81,7 +81,7 @@ public:
// BasicLockable concept // BasicLockable concept
inline void unlock() noexcept { inline void unlock() noexcept {
Q_ASSERT(d_ptr.load()); //mutex must be locked Q_ASSERT(d_ptr.loadRelaxed()); //mutex must be locked
if (!fastTryUnlock()) if (!fastTryUnlock())
unlockInternal(); unlockInternal();
} }

View File

@ -149,7 +149,7 @@ bool lockInternal_helper(QBasicAtomicPointer<QMutexData> &d_ptr, int timeout = -
} }
} }
Q_ASSERT(d_ptr.load()); Q_ASSERT(d_ptr.loadRelaxed());
return true; return true;
} }
@ -169,7 +169,7 @@ bool QBasicMutex::lockInternal(int timeout) noexcept
void QBasicMutex::unlockInternal() noexcept void QBasicMutex::unlockInternal() noexcept
{ {
QMutexData *d = d_ptr.load(); QMutexData *d = d_ptr.loadRelaxed();
Q_ASSERT(d); //we must be locked Q_ASSERT(d); //we must be locked
Q_ASSERT(d != dummyLocked()); // testAndSetRelease(dummyLocked(), 0) failed Q_ASSERT(d != dummyLocked()); // testAndSetRelease(dummyLocked(), 0) failed
Q_UNUSED(d); Q_UNUSED(d);

View File

@ -99,21 +99,21 @@ public:
int id; int id;
bool ref() { bool ref() {
Q_ASSERT(refCount.load() >= 0); Q_ASSERT(refCount.loadRelaxed() >= 0);
int c; int c;
do { do {
c = refCount.load(); c = refCount.loadRelaxed();
if (c == 0) if (c == 0)
return false; return false;
} while (!refCount.testAndSetRelaxed(c, c + 1)); } while (!refCount.testAndSetRelaxed(c, c + 1));
Q_ASSERT(refCount.load() >= 0); Q_ASSERT(refCount.loadRelaxed() >= 0);
return true; return true;
} }
void deref() { void deref() {
Q_ASSERT(refCount.load() >= 0); Q_ASSERT(refCount.loadRelaxed() >= 0);
if (!refCount.deref()) if (!refCount.deref())
release(); release();
Q_ASSERT(refCount.load() >= 0); Q_ASSERT(refCount.loadRelaxed() >= 0);
} }
void release(); void release();
static QMutexPrivate *allocate(); static QMutexPrivate *allocate();

View File

@ -93,7 +93,7 @@ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size)
: mutexes(size), recursionMode(recursionMode) : mutexes(size), recursionMode(recursionMode)
{ {
for (int index = 0; index < mutexes.count(); ++index) { for (int index = 0; index < mutexes.count(); ++index) {
mutexes[index].store(0); mutexes[index].storeRelaxed(0);
} }
} }
@ -104,7 +104,7 @@ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size)
QMutexPool::~QMutexPool() QMutexPool::~QMutexPool()
{ {
for (int index = 0; index < mutexes.count(); ++index) for (int index = 0; index < mutexes.count(); ++index)
delete mutexes[index].load(); delete mutexes[index].loadRelaxed();
} }
/*! /*!
@ -131,7 +131,7 @@ QMutex *QMutexPool::createMutex(int index)
QMutex *newMutex = new QMutex(recursionMode); QMutex *newMutex = new QMutex(recursionMode);
if (!mutexes[index].testAndSetRelease(0, newMutex)) if (!mutexes[index].testAndSetRelease(0, newMutex))
delete newMutex; delete newMutex;
return mutexes[index].load(); return mutexes[index].loadRelaxed();
} }
/*! /*!

View File

@ -68,7 +68,7 @@ public:
inline QMutex *get(const void *address) { inline QMutex *get(const void *address) {
int index = uint(quintptr(address)) % mutexes.count(); int index = uint(quintptr(address)) % mutexes.count();
QMutex *m = mutexes[index].load(); QMutex *m = mutexes[index].loadRelaxed();
if (m) if (m)
return m; return m;
else else

View File

@ -143,7 +143,7 @@ inline bool isUncontendedLocked(const QReadWriteLockPrivate *d)
QReadWriteLock::QReadWriteLock(RecursionMode recursionMode) QReadWriteLock::QReadWriteLock(RecursionMode recursionMode)
: d_ptr(recursionMode == Recursive ? new QReadWriteLockPrivate(true) : nullptr) : d_ptr(recursionMode == Recursive ? new QReadWriteLockPrivate(true) : nullptr)
{ {
Q_ASSERT_X(!(quintptr(d_ptr.load()) & StateMask), "QReadWriteLock::QReadWriteLock", "bad d_ptr alignment"); Q_ASSERT_X(!(quintptr(d_ptr.loadRelaxed()) & StateMask), "QReadWriteLock::QReadWriteLock", "bad d_ptr alignment");
} }
/*! /*!
@ -154,7 +154,7 @@ QReadWriteLock::QReadWriteLock(RecursionMode recursionMode)
*/ */
QReadWriteLock::~QReadWriteLock() QReadWriteLock::~QReadWriteLock()
{ {
auto d = d_ptr.load(); auto d = d_ptr.loadRelaxed();
if (isUncontendedLocked(d)) { if (isUncontendedLocked(d)) {
qWarning("QReadWriteLock: destroying locked QReadWriteLock"); qWarning("QReadWriteLock: destroying locked QReadWriteLock");
return; return;
@ -263,7 +263,7 @@ bool QReadWriteLock::tryLockForRead(int timeout)
return d->recursiveLockForRead(timeout); return d->recursiveLockForRead(timeout);
QMutexLocker lock(&d->mutex); QMutexLocker lock(&d->mutex);
if (d != d_ptr.load()) { if (d != d_ptr.loadRelaxed()) {
// d_ptr has changed: this QReadWriteLock was unlocked before we had // d_ptr has changed: this QReadWriteLock was unlocked before we had
// time to lock d->mutex. // time to lock d->mutex.
// We are holding a lock to a mutex within a QReadWriteLockPrivate // We are holding a lock to a mutex within a QReadWriteLockPrivate
@ -370,7 +370,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout)
return d->recursiveLockForWrite(timeout); return d->recursiveLockForWrite(timeout);
QMutexLocker lock(&d->mutex); QMutexLocker lock(&d->mutex);
if (d != d_ptr.load()) { if (d != d_ptr.loadRelaxed()) {
// The mutex was unlocked before we had time to lock the mutex. // The mutex was unlocked before we had time to lock the mutex.
// We are holding to a mutex within a QReadWriteLockPrivate that is already released // We are holding to a mutex within a QReadWriteLockPrivate that is already released
// (or even is already re-used) but that's ok because the QFreeList never frees them. // (or even is already re-used) but that's ok because the QFreeList never frees them.
@ -433,7 +433,7 @@ void QReadWriteLock::unlock()
if (d->waitingReaders || d->waitingWriters) { if (d->waitingReaders || d->waitingWriters) {
d->unlock(); d->unlock();
} else { } else {
Q_ASSERT(d_ptr.load() == d); // should not change when we still hold the mutex Q_ASSERT(d_ptr.loadRelaxed() == d); // should not change when we still hold the mutex
d_ptr.storeRelease(nullptr); d_ptr.storeRelease(nullptr);
d->release(); d->release();
} }
@ -444,7 +444,7 @@ void QReadWriteLock::unlock()
/*! \internal Helper for QWaitCondition::wait */ /*! \internal Helper for QWaitCondition::wait */
QReadWriteLock::StateForWaitCondition QReadWriteLock::stateForWaitCondition() const QReadWriteLock::StateForWaitCondition QReadWriteLock::stateForWaitCondition() const
{ {
QReadWriteLockPrivate *d = d_ptr.load(); QReadWriteLockPrivate *d = d_ptr.loadRelaxed();
switch (quintptr(d) & StateMask) { switch (quintptr(d) & StateMask) {
case StateLockedForRead: return LockedForRead; case StateLockedForRead: return LockedForRead;
case StateLockedForWrite: return LockedForWrite; case StateLockedForWrite: return LockedForWrite;

View File

@ -264,7 +264,7 @@ template <bool IsTimed> bool futexSemaphoreTryAcquire(QBasicAtomicInteger<quintp
if (futexHasWaiterCount) { if (futexHasWaiterCount) {
// decrement the number of threads waiting // decrement the number of threads waiting
Q_ASSERT(futexHigh32(&u)->load() & 0x7fffffffU); Q_ASSERT(futexHigh32(&u)->loadRelaxed() & 0x7fffffffU);
u.fetchAndSubRelaxed(oneWaiter); u.fetchAndSubRelaxed(oneWaiter);
} }
return false; return false;
@ -293,7 +293,7 @@ QSemaphore::QSemaphore(int n)
quintptr nn = unsigned(n); quintptr nn = unsigned(n);
if (futexHasWaiterCount) if (futexHasWaiterCount)
nn |= quint64(nn) << 32; // token count replicated in high word nn |= quint64(nn) << 32; // token count replicated in high word
u.store(nn); u.storeRelaxed(nn);
} else { } else {
d = new QSemaphorePrivate(n); d = new QSemaphorePrivate(n);
} }
@ -425,7 +425,7 @@ void QSemaphore::release(int n)
int QSemaphore::available() const int QSemaphore::available() const
{ {
if (futexAvailable()) if (futexAvailable())
return futexAvailCounter(u.load()); return futexAvailCounter(u.loadRelaxed());
QMutexLocker locker(&d->mutex); QMutexLocker locker(&d->mutex);
return d->avail; return d->avail;

View File

@ -65,7 +65,7 @@ QThreadData::QThreadData(int initialRefCount)
QThreadData::~QThreadData() QThreadData::~QThreadData()
{ {
Q_ASSERT(_ref.load() == 0); Q_ASSERT(_ref.loadRelaxed() == 0);
// In the odd case that Qt is running on a secondary thread, the main // In the odd case that Qt is running on a secondary thread, the main
// thread instance will have been dereffed asunder because of the deref in // thread instance will have been dereffed asunder because of the deref in
@ -105,7 +105,7 @@ void QThreadData::ref()
{ {
#if QT_CONFIG(thread) #if QT_CONFIG(thread)
(void) _ref.ref(); (void) _ref.ref();
Q_ASSERT(_ref.load() != 0); Q_ASSERT(_ref.loadRelaxed() != 0);
#endif #endif
} }
@ -878,11 +878,11 @@ QThreadData *QThreadData::current(bool createIfNecessary)
if (!data && createIfNecessary) { if (!data && createIfNecessary) {
data = new QThreadData; data = new QThreadData;
data->thread = new QAdoptedThread(data); data->thread = new QAdoptedThread(data);
data->threadId.store(Qt::HANDLE(data->thread)); data->threadId.storeRelaxed(Qt::HANDLE(data->thread));
data->deref(); data->deref();
data->isAdopted = true; data->isAdopted = true;
if (!QCoreApplicationPrivate::theMainThread) if (!QCoreApplicationPrivate::theMainThread)
QCoreApplicationPrivate::theMainThread = data->thread.load(); QCoreApplicationPrivate::theMainThread = data->thread.loadRelaxed();
} }
return data; return data;
} }
@ -925,7 +925,7 @@ QThreadPrivate::~QThreadPrivate()
QAbstractEventDispatcher *QThread::eventDispatcher() const QAbstractEventDispatcher *QThread::eventDispatcher() const
{ {
Q_D(const QThread); Q_D(const QThread);
return d->data->eventDispatcher.load(); return d->data->eventDispatcher.loadRelaxed();
} }
/*! /*!

View File

@ -257,11 +257,11 @@ public:
void ref(); void ref();
void deref(); void deref();
inline bool hasEventDispatcher() const inline bool hasEventDispatcher() const
{ return eventDispatcher.load() != nullptr; } { return eventDispatcher.loadRelaxed() != nullptr; }
QAbstractEventDispatcher *createEventDispatcher(); QAbstractEventDispatcher *createEventDispatcher();
QAbstractEventDispatcher *ensureEventDispatcher() QAbstractEventDispatcher *ensureEventDispatcher()
{ {
QAbstractEventDispatcher *ed = eventDispatcher.load(); QAbstractEventDispatcher *ed = eventDispatcher.loadRelaxed();
if (Q_LIKELY(ed)) if (Q_LIKELY(ed))
return ed; return ed;
return createEventDispatcher(); return createEventDispatcher();

View File

@ -252,9 +252,9 @@ QThreadData *QThreadData::current(bool createIfNecessary)
} }
data->deref(); data->deref();
data->isAdopted = true; data->isAdopted = true;
data->threadId.store(to_HANDLE(pthread_self())); data->threadId.storeRelaxed(to_HANDLE(pthread_self()));
if (!QCoreApplicationPrivate::theMainThread) if (!QCoreApplicationPrivate::theMainThread)
QCoreApplicationPrivate::theMainThread = data->thread.load(); QCoreApplicationPrivate::theMainThread = data->thread.loadRelaxed();
} }
return data; return data;
} }
@ -334,7 +334,7 @@ void *QThreadPrivate::start(void *arg)
thr->d_func()->setPriority(QThread::Priority(thr->d_func()->priority & ~ThreadPriorityResetFlag)); thr->d_func()->setPriority(QThread::Priority(thr->d_func()->priority & ~ThreadPriorityResetFlag));
} }
data->threadId.store(to_HANDLE(pthread_self())); data->threadId.storeRelaxed(to_HANDLE(pthread_self()));
set_thread_data(data); set_thread_data(data);
data->ref(); data->ref();
@ -404,7 +404,7 @@ void QThreadPrivate::finish(void *arg)
QThreadStorageData::finish((void **)data); QThreadStorageData::finish((void **)data);
locker.relock(); locker.relock();
QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher.load(); QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher.loadRelaxed();
if (eventDispatcher) { if (eventDispatcher) {
d->data->eventDispatcher = 0; d->data->eventDispatcher = 0;
locker.unlock(); locker.unlock();
@ -737,7 +737,7 @@ void QThread::start(Priority priority)
#endif #endif
code = pthread_create(&threadId, &attr, QThreadPrivate::start, this); code = pthread_create(&threadId, &attr, QThreadPrivate::start, this);
} }
d->data->threadId.store(to_HANDLE(threadId)); d->data->threadId.storeRelaxed(to_HANDLE(threadId));
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
@ -746,7 +746,7 @@ void QThread::start(Priority priority)
d->running = false; d->running = false;
d->finished = false; d->finished = false;
d->data->threadId.store(nullptr); d->data->threadId.storeRelaxed(nullptr);
} }
} }
@ -756,10 +756,10 @@ void QThread::terminate()
Q_D(QThread); Q_D(QThread);
QMutexLocker locker(&d->mutex); QMutexLocker locker(&d->mutex);
if (!d->data->threadId.load()) if (!d->data->threadId.loadRelaxed())
return; return;
int code = pthread_cancel(from_HANDLE<pthread_t>(d->data->threadId.load())); int code = pthread_cancel(from_HANDLE<pthread_t>(d->data->threadId.loadRelaxed()));
if (code) { if (code) {
qErrnoWarning(code, "QThread::start: Thread termination error"); qErrnoWarning(code, "QThread::start: Thread termination error");
} }
@ -771,7 +771,7 @@ bool QThread::wait(unsigned long time)
Q_D(QThread); Q_D(QThread);
QMutexLocker locker(&d->mutex); QMutexLocker locker(&d->mutex);
if (from_HANDLE<pthread_t>(d->data->threadId.load()) == pthread_self()) { if (from_HANDLE<pthread_t>(d->data->threadId.loadRelaxed()) == pthread_self()) {
qWarning("QThread::wait: Thread tried to wait on itself"); qWarning("QThread::wait: Thread tried to wait on itself");
return false; return false;
} }
@ -813,7 +813,7 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority)
int sched_policy; int sched_policy;
sched_param param; sched_param param;
if (pthread_getschedparam(from_HANDLE<pthread_t>(data->threadId.load()), &sched_policy, &param) != 0) { if (pthread_getschedparam(from_HANDLE<pthread_t>(data->threadId.loadRelaxed()), &sched_policy, &param) != 0) {
// failed to get the scheduling policy, don't bother setting // failed to get the scheduling policy, don't bother setting
// the priority // the priority
qWarning("QThread::setPriority: Cannot get scheduler parameters"); qWarning("QThread::setPriority: Cannot get scheduler parameters");
@ -829,15 +829,15 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority)
} }
param.sched_priority = prio; param.sched_priority = prio;
int status = pthread_setschedparam(from_HANDLE<pthread_t>(data->threadId.load()), sched_policy, &param); int status = pthread_setschedparam(from_HANDLE<pthread_t>(data->threadId.loadRelaxed()), sched_policy, &param);
# ifdef SCHED_IDLE # ifdef SCHED_IDLE
// were we trying to set to idle priority and failed? // were we trying to set to idle priority and failed?
if (status == -1 && sched_policy == SCHED_IDLE && errno == EINVAL) { if (status == -1 && sched_policy == SCHED_IDLE && errno == EINVAL) {
// reset to lowest priority possible // reset to lowest priority possible
pthread_getschedparam(from_HANDLE<pthread_t>(data->threadId.load()), &sched_policy, &param); pthread_getschedparam(from_HANDLE<pthread_t>(data->threadId.loadRelaxed()), &sched_policy, &param);
param.sched_priority = sched_get_priority_min(sched_policy); param.sched_priority = sched_get_priority_min(sched_policy);
pthread_setschedparam(from_HANDLE<pthread_t>(data->threadId.load()), sched_policy, &param); pthread_setschedparam(from_HANDLE<pthread_t>(data->threadId.loadRelaxed()), sched_policy, &param);
} }
# else # else
Q_UNUSED(status); Q_UNUSED(status);

View File

@ -138,11 +138,11 @@ QThreadData *QThreadData::current(bool createIfNecessary)
} }
threadData->deref(); threadData->deref();
threadData->isAdopted = true; threadData->isAdopted = true;
threadData->threadId.store(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId()))); threadData->threadId.storeRelaxed(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId())));
#ifndef Q_OS_WINRT #ifndef Q_OS_WINRT
if (!QCoreApplicationPrivate::theMainThread) { if (!QCoreApplicationPrivate::theMainThread) {
QCoreApplicationPrivate::theMainThread = threadData->thread.load(); QCoreApplicationPrivate::theMainThread = threadData->thread.loadRelaxed();
} else { } else {
#else #else
// for winrt the main thread is set explicitly in QCoreApplication's constructor as the // for winrt the main thread is set explicitly in QCoreApplication's constructor as the
@ -184,9 +184,9 @@ void QThreadData::setMainThread()
} }
threadData->deref(); threadData->deref();
threadData->isAdopted = true; threadData->isAdopted = true;
threadData->threadId.store(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId()))); threadData->threadId.storeRelaxed(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId())));
} }
QCoreApplicationPrivate::theMainThread = threadData->thread.load(); QCoreApplicationPrivate::theMainThread = threadData->thread.loadRelaxed();
} }
#endif #endif
@ -379,7 +379,7 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi
qt_create_tls(); qt_create_tls();
TlsSetValue(qt_current_thread_data_tls_index, data); TlsSetValue(qt_current_thread_data_tls_index, data);
data->threadId.store(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId()))); data->threadId.storeRelaxed(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId())));
QThread::setTerminationEnabled(false); QThread::setTerminationEnabled(false);
@ -421,7 +421,7 @@ void QThreadPrivate::finish(void *arg, bool lockAnyway) noexcept
QThreadStorageData::finish(tls_data); QThreadStorageData::finish(tls_data);
locker.relock(); locker.relock();
QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher.load(); QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher.loadRelaxed();
if (eventDispatcher) { if (eventDispatcher) {
d->data->eventDispatcher = 0; d->data->eventDispatcher = 0;
locker.unlock(); locker.unlock();

View File

@ -126,7 +126,7 @@ void **QThreadStorageData::get() const
DEBUG_MSG("QThreadStorageData: Returning storage %d, data %p, for thread %p", DEBUG_MSG("QThreadStorageData: Returning storage %d, data %p, for thread %p",
id, id,
*v, *v,
data->thread.load()); data->thread.loadRelaxed());
return *v ? v : 0; return *v ? v : 0;
} }
@ -148,7 +148,7 @@ void **QThreadStorageData::set(void *p)
DEBUG_MSG("QThreadStorageData: Deleting previous storage %d, data %p, for thread %p", DEBUG_MSG("QThreadStorageData: Deleting previous storage %d, data %p, for thread %p",
id, id,
value, value,
data->thread.load()); data->thread.loadRelaxed());
QMutexLocker locker(&destructorsMutex); QMutexLocker locker(&destructorsMutex);
DestructorMap *destr = destructors(); DestructorMap *destr = destructors();
@ -164,7 +164,7 @@ void **QThreadStorageData::set(void *p)
// store new data // store new data
value = p; value = p;
DEBUG_MSG("QThreadStorageData: Set storage %d for thread %p to %p", id, data->thread.load(), p); DEBUG_MSG("QThreadStorageData: Set storage %d for thread %p to %p", id, data->thread.loadRelaxed(), p);
return &value; return &value;
} }

View File

@ -3181,13 +3181,13 @@ inline void QDateTime::Data::detach()
x->m_status = QDateTimePrivate::StatusFlag(data.status & ~QDateTimePrivate::ShortData); x->m_status = QDateTimePrivate::StatusFlag(data.status & ~QDateTimePrivate::ShortData);
x->m_msecs = data.msecs; x->m_msecs = data.msecs;
} else { } else {
if (d->ref.load() == 1) if (d->ref.loadRelaxed() == 1)
return; return;
x = new QDateTimePrivate(*d); x = new QDateTimePrivate(*d);
} }
x->ref.store(1); x->ref.storeRelaxed(1);
if (!wasShort && !d->ref.deref()) if (!wasShort && !d->ref.deref())
delete d; delete d;
d = x; d = x;
@ -3203,7 +3203,7 @@ inline QDateTimePrivate *QDateTime::Data::operator->()
{ {
// should we attempt to detach here? // should we attempt to detach here?
Q_ASSERT(!isShort()); Q_ASSERT(!isShort());
Q_ASSERT(d->ref.load() == 1); Q_ASSERT(d->ref.loadRelaxed() == 1);
return d; return d;
} }

View File

@ -224,9 +224,9 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
& ~(alignment - 1); & ~(alignment - 1);
#if !defined(QT_NO_UNSHARABLE_CONTAINERS) #if !defined(QT_NO_UNSHARABLE_CONTAINERS)
header->ref.atomic.store(bool(!(options & Unsharable))); header->ref.atomic.storeRelaxed(bool(!(options & Unsharable)));
#else #else
header->ref.atomic.store(1); header->ref.atomic.storeRelaxed(1);
#endif #endif
header->size = 0; header->size = 0;
header->alloc = capacity; header->alloc = capacity;

View File

@ -106,7 +106,7 @@ struct QPodArrayOps
void destroyAll() // Call from destructors, ONLY! void destroyAll() // Call from destructors, ONLY!
{ {
Q_ASSERT(this->isMutable()); Q_ASSERT(this->isMutable());
Q_ASSERT(this->ref.atomic.load() == 0); Q_ASSERT(this->ref.atomic.loadRelaxed() == 0);
// As this is to be called only from destructor, it doesn't need to be // As this is to be called only from destructor, it doesn't need to be
// exception safe; size not updated. // exception safe; size not updated.
@ -204,7 +204,7 @@ struct QGenericArrayOps
// As this is to be called only from destructor, it doesn't need to be // As this is to be called only from destructor, it doesn't need to be
// exception safe; size not updated. // exception safe; size not updated.
Q_ASSERT(this->ref.atomic.load() == 0); Q_ASSERT(this->ref.atomic.loadRelaxed() == 0);
const T *const b = this->begin(); const T *const b = this->begin();
const T *i = this->end(); const T *i = this->end();

View File

@ -166,7 +166,7 @@ QCollator &QCollator::operator=(const QCollator &other)
*/ */
void QCollator::detach() void QCollator::detach()
{ {
if (d->ref.load() != 1) { if (d->ref.loadRelaxed() != 1) {
QCollatorPrivate *x = new QCollatorPrivate(d->locale); QCollatorPrivate *x = new QCollatorPrivate(d->locale);
if (!d->ref.deref()) if (!d->ref.deref())
delete d; delete d;

View File

@ -100,8 +100,8 @@ public:
inline ~QContiguousCache() { if (!d) return; if (!d->ref.deref()) freeData(p); } inline ~QContiguousCache() { if (!d) return; if (!d->ref.deref()) freeData(p); }
inline void detach() { if (d->ref.load() != 1) detach_helper(); } inline void detach() { if (d->ref.loadRelaxed() != 1) detach_helper(); }
inline bool isDetached() const { return d->ref.load() == 1; } inline bool isDetached() const { return d->ref.loadRelaxed() == 1; }
#if !defined(QT_NO_UNSHARABLE_CONTAINERS) #if !defined(QT_NO_UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; }
#endif #endif
@ -176,7 +176,7 @@ void QContiguousCache<T>::detach_helper()
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x; union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
x.d = allocateData(d->alloc); x.d = allocateData(d->alloc);
x.d->ref.store(1); x.d->ref.storeRelaxed(1);
x.d->count = d->count; x.d->count = d->count;
x.d->start = d->start; x.d->start = d->start;
x.d->offset = d->offset; x.d->offset = d->offset;
@ -215,7 +215,7 @@ void QContiguousCache<T>::setCapacity(int asize)
detach(); detach();
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x; union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
x.d = allocateData(asize); x.d = allocateData(asize);
x.d->ref.store(1); x.d->ref.storeRelaxed(1);
x.d->alloc = asize; x.d->alloc = asize;
x.d->count = qMin(d->count, asize); x.d->count = qMin(d->count, asize);
x.d->offset = d->offset + d->count - x.d->count; x.d->offset = d->offset + d->count - x.d->count;
@ -251,7 +251,7 @@ void QContiguousCache<T>::setCapacity(int asize)
template <typename T> template <typename T>
void QContiguousCache<T>::clear() void QContiguousCache<T>::clear()
{ {
if (d->ref.load() == 1) { if (d->ref.loadRelaxed() == 1) {
if (QTypeInfo<T>::isComplex) { if (QTypeInfo<T>::isComplex) {
int oldcount = d->count; int oldcount = d->count;
T * i = p->array + d->start; T * i = p->array + d->start;
@ -267,7 +267,7 @@ void QContiguousCache<T>::clear()
} else { } else {
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x; union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
x.d = allocateData(d->alloc); x.d = allocateData(d->alloc);
x.d->ref.store(1); x.d->ref.storeRelaxed(1);
x.d->alloc = d->alloc; x.d->alloc = d->alloc;
x.d->count = x.d->start = x.d->offset = 0; x.d->count = x.d->start = x.d->offset = 0;
x.d->sharable = true; x.d->sharable = true;
@ -287,7 +287,7 @@ QContiguousCache<T>::QContiguousCache(int cap)
{ {
Q_ASSERT(cap >= 0); Q_ASSERT(cap >= 0);
d = allocateData(cap); d = allocateData(cap);
d->ref.store(1); d->ref.storeRelaxed(1);
d->alloc = cap; d->alloc = cap;
d->count = d->start = d->offset = 0; d->count = d->start = d->offset = 0;
d->sharable = true; d->sharable = true;

View File

@ -171,7 +171,7 @@ class QFreeList
// qDebug("QFreeList: allocating %d elements (%ld bytes) with offset %d", size, size * sizeof(ElementType), offset); // qDebug("QFreeList: allocating %d elements (%ld bytes) with offset %d", size, size * sizeof(ElementType), offset);
ElementType *v = new ElementType[size]; ElementType *v = new ElementType[size];
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
v[i].next.store(offset + i + 1); v[i].next.storeRelaxed(offset + i + 1);
return v; return v;
} }
@ -218,21 +218,21 @@ template <typename T, typename ConstantsType>
inline QFreeList<T, ConstantsType>::~QFreeList() inline QFreeList<T, ConstantsType>::~QFreeList()
{ {
for (int i = 0; i < ConstantsType::BlockCount; ++i) for (int i = 0; i < ConstantsType::BlockCount; ++i)
delete [] _v[i].load(); delete [] _v[i].loadRelaxed();
} }
template <typename T, typename ConstantsType> template <typename T, typename ConstantsType>
inline typename QFreeList<T, ConstantsType>::ConstReferenceType QFreeList<T, ConstantsType>::at(int x) const inline typename QFreeList<T, ConstantsType>::ConstReferenceType QFreeList<T, ConstantsType>::at(int x) const
{ {
const int block = blockfor(x); const int block = blockfor(x);
return (_v[block].load())[x].t(); return (_v[block].loadRelaxed())[x].t();
} }
template <typename T, typename ConstantsType> template <typename T, typename ConstantsType>
inline typename QFreeList<T, ConstantsType>::ReferenceType QFreeList<T, ConstantsType>::operator[](int x) inline typename QFreeList<T, ConstantsType>::ReferenceType QFreeList<T, ConstantsType>::operator[](int x)
{ {
const int block = blockfor(x); const int block = blockfor(x);
return (_v[block].load())[x].t(); return (_v[block].loadRelaxed())[x].t();
} }
template <typename T, typename ConstantsType> template <typename T, typename ConstantsType>
@ -257,7 +257,7 @@ inline int QFreeList<T, ConstantsType>::next()
} }
} }
newid = v[at].next.load() | (id & ~ConstantsType::IndexMask); newid = v[at].next.loadRelaxed() | (id & ~ConstantsType::IndexMask);
} while (!_next.testAndSetRelease(id, newid)); } while (!_next.testAndSetRelease(id, newid));
// qDebug("QFreeList::next(): returning %d (_next now %d, serial %d)", // qDebug("QFreeList::next(): returning %d (_next now %d, serial %d)",
// id & ConstantsType::IndexMask, // id & ConstantsType::IndexMask,
@ -271,12 +271,12 @@ inline void QFreeList<T, ConstantsType>::release(int id)
{ {
int at = id & ConstantsType::IndexMask; int at = id & ConstantsType::IndexMask;
const int block = blockfor(at); const int block = blockfor(at);
ElementType *v = _v[block].load(); ElementType *v = _v[block].loadRelaxed();
int x, newid; int x, newid;
do { do {
x = _next.loadAcquire(); x = _next.loadAcquire();
v[at].next.store(x & ConstantsType::IndexMask); v[at].next.storeRelaxed(x & ConstantsType::IndexMask);
newid = incrementserial(x, id); newid = incrementserial(x, id);
} while (!_next.testAndSetRelease(x, newid)); } while (!_next.testAndSetRelease(x, newid));

View File

@ -321,7 +321,7 @@ static QBasicAtomicInt qt_qhash_seed = Q_BASIC_ATOMIC_INITIALIZER(-1);
*/ */
static void qt_initialize_qhash_seed() static void qt_initialize_qhash_seed()
{ {
if (qt_qhash_seed.load() == -1) { if (qt_qhash_seed.loadRelaxed() == -1) {
int x(qt_create_qhash_seed() & INT_MAX); int x(qt_create_qhash_seed() & INT_MAX);
qt_qhash_seed.testAndSetRelaxed(-1, x); qt_qhash_seed.testAndSetRelaxed(-1, x);
} }
@ -340,7 +340,7 @@ static void qt_initialize_qhash_seed()
int qGlobalQHashSeed() int qGlobalQHashSeed()
{ {
qt_initialize_qhash_seed(); qt_initialize_qhash_seed();
return qt_qhash_seed.load(); return qt_qhash_seed.loadRelaxed();
} }
/*! \relates QHash /*! \relates QHash
@ -372,14 +372,14 @@ void qSetGlobalQHashSeed(int newSeed)
return; return;
if (newSeed == -1) { if (newSeed == -1) {
int x(qt_create_qhash_seed() & INT_MAX); int x(qt_create_qhash_seed() & INT_MAX);
qt_qhash_seed.store(x); qt_qhash_seed.storeRelaxed(x);
} else { } else {
if (newSeed) { if (newSeed) {
// can't use qWarning here (reentrancy) // can't use qWarning here (reentrancy)
fprintf(stderr, "qSetGlobalQHashSeed: forced seed value is not 0, cannot guarantee that the " fprintf(stderr, "qSetGlobalQHashSeed: forced seed value is not 0, cannot guarantee that the "
"hashing functions will produce a stable value."); "hashing functions will produce a stable value.");
} }
qt_qhash_seed.store(newSeed & INT_MAX); qt_qhash_seed.storeRelaxed(newSeed & INT_MAX);
} }
} }
@ -509,7 +509,7 @@ QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *),
d->userNumBits = userNumBits; d->userNumBits = userNumBits;
d->numBits = numBits; d->numBits = numBits;
d->numBuckets = numBuckets; d->numBuckets = numBuckets;
d->seed = (this == &shared_null) ? uint(qt_qhash_seed.load()) : seed; d->seed = (this == &shared_null) ? uint(qt_qhash_seed.loadRelaxed()) : seed;
d->sharable = true; d->sharable = true;
d->strictAlignment = nodeAlign > 8; d->strictAlignment = nodeAlign > 8;
d->reserved = 0; d->reserved = 0;

View File

@ -340,7 +340,7 @@ void QLinkedList<T>::freeData(QLinkedListData *x)
{ {
Node *y = reinterpret_cast<Node*>(x); Node *y = reinterpret_cast<Node*>(x);
Node *i = y->n; Node *i = y->n;
Q_ASSERT(x->ref.atomic.load() == 0); Q_ASSERT(x->ref.atomic.loadRelaxed() == 0);
while (i != y) { while (i != y) {
Node *n = i; Node *n = i;
i = i->n; i = i->n;

View File

@ -337,7 +337,7 @@ public:
{ {
QLocalePrivate *retval = new QLocalePrivate; QLocalePrivate *retval = new QLocalePrivate;
retval->m_data = data; retval->m_data = data;
retval->ref.store(0); retval->ref.storeRelaxed(0);
retval->m_numberOptions = numberOptions; retval->m_numberOptions = numberOptions;
return retval; return retval;
} }

View File

@ -52,7 +52,7 @@ class RefCount
{ {
public: public:
inline bool ref() noexcept { inline bool ref() noexcept {
int count = atomic.load(); int count = atomic.loadRelaxed();
#if !defined(QT_NO_UNSHARABLE_CONTAINERS) #if !defined(QT_NO_UNSHARABLE_CONTAINERS)
if (count == 0) // !isSharable if (count == 0) // !isSharable
return false; return false;
@ -63,7 +63,7 @@ public:
} }
inline bool deref() noexcept { inline bool deref() noexcept {
int count = atomic.load(); int count = atomic.loadRelaxed();
#if !defined(QT_NO_UNSHARABLE_CONTAINERS) #if !defined(QT_NO_UNSHARABLE_CONTAINERS)
if (count == 0) // !isSharable if (count == 0) // !isSharable
return false; return false;
@ -86,24 +86,24 @@ public:
bool isSharable() const noexcept bool isSharable() const noexcept
{ {
// Sharable === Shared ownership. // Sharable === Shared ownership.
return atomic.load() != 0; return atomic.loadRelaxed() != 0;
} }
#endif #endif
bool isStatic() const noexcept bool isStatic() const noexcept
{ {
// Persistent object, never deleted // Persistent object, never deleted
return atomic.load() == -1; return atomic.loadRelaxed() == -1;
} }
bool isShared() const noexcept bool isShared() const noexcept
{ {
int count = atomic.load(); int count = atomic.loadRelaxed();
return (count != 1) && (count != 0); return (count != 1) && (count != 0);
} }
void initializeOwned() noexcept { atomic.store(1); } void initializeOwned() noexcept { atomic.storeRelaxed(1); }
void initializeUnsharable() noexcept { atomic.store(0); } void initializeUnsharable() noexcept { atomic.storeRelaxed(0); }
QBasicAtomicInt atomic; QBasicAtomicInt atomic;
}; };

View File

@ -1707,7 +1707,7 @@ void QRegExpEngine::dump() const
void QRegExpEngine::setup() void QRegExpEngine::setup()
{ {
ref.store(1); ref.storeRelaxed(1);
#ifndef QT_NO_REGEXP_CAPTURE #ifndef QT_NO_REGEXP_CAPTURE
f.resize(32); f.resize(32);
nf = 0; nf = 0;

View File

@ -75,7 +75,7 @@ public:
typedef T Type; typedef T Type;
typedef T *pointer; typedef T *pointer;
inline void detach() { if (d && d->ref.load() != 1) detach_helper(); } inline void detach() { if (d && d->ref.loadRelaxed() != 1) detach_helper(); }
inline T &operator*() { detach(); return *d; } inline T &operator*() { detach(); return *d; }
inline const T &operator*() const { return *d; } inline const T &operator*() const { return *d; }
inline T *operator->() { detach(); return d; } inline T *operator->() { detach(); return d; }
@ -163,7 +163,7 @@ public:
inline const T *constData() const { return d; } inline const T *constData() const { return d; }
inline T *take() { T *x = d; d = nullptr; return x; } inline T *take() { T *x = d; d = nullptr; return x; }
inline void detach() { if (d && d->ref.load() != 1) detach_helper(); } inline void detach() { if (d && d->ref.loadRelaxed() != 1) detach_helper(); }
inline void reset() inline void reset()
{ {

View File

@ -1380,7 +1380,7 @@ void QtSharedPointer::ExternalRefCountData::setQObjectShared(const QObject *, bo
*/ */
void QtSharedPointer::ExternalRefCountData::checkQObjectShared(const QObject *) void QtSharedPointer::ExternalRefCountData::checkQObjectShared(const QObject *)
{ {
if (strongref.load() < 0) if (strongref.loadRelaxed() < 0)
qWarning("QSharedPointer: cannot create a QSharedPointer from a QObject-tracking QWeakPointer"); qWarning("QSharedPointer: cannot create a QSharedPointer from a QObject-tracking QWeakPointer");
} }
@ -1390,7 +1390,7 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject *>(obj)); QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject *>(obj));
Q_ASSERT_X(!d->wasDeleted, "QWeakPointer", "Detected QWeakPointer creation in a QObject being deleted"); Q_ASSERT_X(!d->wasDeleted, "QWeakPointer", "Detected QWeakPointer creation in a QObject being deleted");
ExternalRefCountData *that = d->sharedRefcount.load(); ExternalRefCountData *that = d->sharedRefcount.loadRelaxed();
if (that) { if (that) {
that->weakref.ref(); that->weakref.ref();
return that; return that;
@ -1398,8 +1398,8 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
// we can create the refcount data because it doesn't exist // we can create the refcount data because it doesn't exist
ExternalRefCountData *x = new ExternalRefCountData(Qt::Uninitialized); ExternalRefCountData *x = new ExternalRefCountData(Qt::Uninitialized);
x->strongref.store(-1); x->strongref.storeRelaxed(-1);
x->weakref.store(2); // the QWeakPointer that called us plus the QObject itself x->weakref.storeRelaxed(2); // the QWeakPointer that called us plus the QObject itself
ExternalRefCountData *ret; ExternalRefCountData *ret;
if (d->sharedRefcount.testAndSetOrdered(nullptr, x, ret)) { // ought to be release+acquire; this is acq_rel+acquire if (d->sharedRefcount.testAndSetOrdered(nullptr, x, ret)) { // ought to be release+acquire; this is acq_rel+acquire
@ -1407,7 +1407,7 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
} else { } else {
// ~ExternalRefCountData has a Q_ASSERT, so we use this trick to // ~ExternalRefCountData has a Q_ASSERT, so we use this trick to
// only execute this if Q_ASSERTs are enabled // only execute this if Q_ASSERTs are enabled
Q_ASSERT((x->weakref.store(0), true)); Q_ASSERT((x->weakref.storeRelaxed(0), true));
delete x; delete x;
ret->weakref.ref(); ret->weakref.ref();
} }

View File

@ -154,11 +154,11 @@ namespace QtSharedPointer {
inline ExternalRefCountData(DestroyerFn d) inline ExternalRefCountData(DestroyerFn d)
: destroyer(d) : destroyer(d)
{ {
strongref.store(1); strongref.storeRelaxed(1);
weakref.store(1); weakref.storeRelaxed(1);
} }
inline ExternalRefCountData(Qt::Initialization) { } inline ExternalRefCountData(Qt::Initialization) { }
~ExternalRefCountData() { Q_ASSERT(!weakref.load()); Q_ASSERT(strongref.load() <= 0); } ~ExternalRefCountData() { Q_ASSERT(!weakref.loadRelaxed()); Q_ASSERT(strongref.loadRelaxed() <= 0); }
void destroy() { destroyer(this); } void destroy() { destroyer(this); }
@ -522,12 +522,12 @@ public:
if (o) { if (o) {
// increase the strongref, but never up from zero // increase the strongref, but never up from zero
// or less (-1 is used by QWeakPointer on untracked QObject) // or less (-1 is used by QWeakPointer on untracked QObject)
int tmp = o->strongref.load(); int tmp = o->strongref.loadRelaxed();
while (tmp > 0) { while (tmp > 0) {
// try to increment from "tmp" to "tmp + 1" // try to increment from "tmp" to "tmp + 1"
if (o->strongref.testAndSetRelaxed(tmp, tmp + 1)) if (o->strongref.testAndSetRelaxed(tmp, tmp + 1))
break; // succeeded break; // succeeded
tmp = o->strongref.load(); // failed, try again tmp = o->strongref.loadRelaxed(); // failed, try again
} }
if (tmp > 0) { if (tmp > 0) {
@ -540,7 +540,7 @@ public:
qSwap(d, o); qSwap(d, o);
qSwap(this->value, actual); qSwap(this->value, actual);
if (!d || d->strongref.load() == 0) if (!d || d->strongref.loadRelaxed() == 0)
this->value = nullptr; this->value = nullptr;
// dereference saved data // dereference saved data
@ -566,7 +566,7 @@ public:
typedef const value_type &const_reference; typedef const value_type &const_reference;
typedef qptrdiff difference_type; typedef qptrdiff difference_type;
bool isNull() const noexcept { return d == nullptr || d->strongref.load() == 0 || value == nullptr; } bool isNull() const noexcept { return d == nullptr || d->strongref.loadRelaxed() == 0 || value == nullptr; }
operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QWeakPointer::value; } operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QWeakPointer::value; }
bool operator !() const noexcept { return isNull(); } bool operator !() const noexcept { return isNull(); }
@ -709,7 +709,7 @@ public:
// a weak pointer's data but the weak pointer itself // a weak pointer's data but the weak pointer itself
inline T *internalData() const noexcept inline T *internalData() const noexcept
{ {
return d == nullptr || d->strongref.load() == 0 ? nullptr : value; return d == nullptr || d->strongref.loadRelaxed() == 0 ? nullptr : value;
} }
Data *d; Data *d;

View File

@ -563,9 +563,9 @@ quint64 qDetectCpuFeatures()
features_string + features_indices[qCountTrailingZeroBits(missing)]); features_string + features_indices[qCountTrailingZeroBits(missing)]);
} }
qt_cpu_features[0].store(f | quint32(QSimdInitialized)); qt_cpu_features[0].storeRelaxed(f | quint32(QSimdInitialized));
#ifndef Q_ATOMIC_INT64_IS_SUPPORTED #ifndef Q_ATOMIC_INT64_IS_SUPPORTED
qt_cpu_features[1].store(f >> 32); qt_cpu_features[1].storeRelaxed(f >> 32);
#endif #endif
return f; return f;
} }

View File

@ -348,9 +348,9 @@ Q_CORE_EXPORT quint64 qDetectCpuFeatures();
static inline quint64 qCpuFeatures() static inline quint64 qCpuFeatures()
{ {
quint64 features = qt_cpu_features[0].load(); quint64 features = qt_cpu_features[0].loadRelaxed();
#ifndef Q_ATOMIC_INT64_IS_SUPPORTED #ifndef Q_ATOMIC_INT64_IS_SUPPORTED
features |= quint64(qt_cpu_features[1].load()) << 32; features |= quint64(qt_cpu_features[1].loadRelaxed()) << 32;
#endif #endif
if (Q_UNLIKELY(features == 0)) { if (Q_UNLIKELY(features == 0)) {
features = qDetectCpuFeatures(); features = qDetectCpuFeatures();

View File

@ -111,7 +111,7 @@ bool QDBusArgumentPrivate::checkWrite(QDBusArgumentPrivate *&d)
if (!d->marshaller()->ok) if (!d->marshaller()->ok)
return false; return false;
if (d->message && d->ref.load() != 1) { if (d->message && d->ref.loadRelaxed() != 1) {
QDBusMarshaller *dd = new QDBusMarshaller(d->capabilities); QDBusMarshaller *dd = new QDBusMarshaller(d->capabilities);
dd->message = q_dbus_message_copy(d->message); dd->message = q_dbus_message_copy(d->message);
q_dbus_message_iter_init_append(dd->message, &dd->iterator); q_dbus_message_iter_init_append(dd->message, &dd->iterator);
@ -152,7 +152,7 @@ bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d)
if (!checkRead(d)) if (!checkRead(d))
return false; // don't bother return false; // don't bother
if (d->ref.load() == 1) if (d->ref.loadRelaxed() == 1)
return true; // no need to detach return true; // no need to detach
QDBusDemarshaller *dd = new QDBusDemarshaller(d->capabilities); QDBusDemarshaller *dd = new QDBusDemarshaller(d->capabilities);

View File

@ -534,7 +534,7 @@ qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data)
bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg) bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg)
{ {
if (!ref.load()) if (!ref.loadRelaxed())
return false; return false;
// local message are always delivered, regardless of filtering // local message are always delivered, regardless of filtering
@ -1077,7 +1077,7 @@ QDBusConnectionPrivate::~QDBusConnectionPrivate()
if (lastMode == ClientMode || lastMode == PeerMode) { if (lastMode == ClientMode || lastMode == PeerMode) {
// the bus service object holds a reference back to us; // the bus service object holds a reference back to us;
// we need to destroy it before we finish destroying ourselves // we need to destroy it before we finish destroying ourselves
Q_ASSERT(ref.load() == 0); Q_ASSERT(ref.loadRelaxed() == 0);
QObject *obj = (QObject *)busService; QObject *obj = (QObject *)busService;
if (obj) { if (obj) {
disconnect(obj, nullptr, this, nullptr); disconnect(obj, nullptr, this, nullptr);
@ -2126,11 +2126,11 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM
if ((receiver && returnMethod) || errorMethod) { if ((receiver && returnMethod) || errorMethod) {
// no one waiting, will delete pcall in processFinishedCall() // no one waiting, will delete pcall in processFinishedCall()
pcall->ref.store(1); pcall->ref.storeRelaxed(1);
} else { } else {
// set double ref to prevent race between processFinishedCall() and ref counting // set double ref to prevent race between processFinishedCall() and ref counting
// by QDBusPendingCall::QExplicitlySharedDataPointer<QDBusPendingCallPrivate> // by QDBusPendingCall::QExplicitlySharedDataPointer<QDBusPendingCallPrivate>
pcall->ref.store(2); pcall->ref.storeRelaxed(2);
} }
if (isLoopback) { if (isLoopback) {

View File

@ -93,7 +93,7 @@ void QDBusMetaTypeId::init()
// reentrancy is not a problem since everything else is locked on their own // reentrancy is not a problem since everything else is locked on their own
// set the guard variable at the end // set the guard variable at the end
if (!initialized.load()) { if (!initialized.loadRelaxed()) {
// register our types with Qt Core (calling qMetaTypeId<T>() does this implicitly) // register our types with Qt Core (calling qMetaTypeId<T>() does this implicitly)
(void)message(); (void)message();
(void)argument(); (void)argument();
@ -145,7 +145,7 @@ void QDBusMetaTypeId::init()
qDBusRegisterMetaType<QVector<QDBusUnixFileDescriptor> >(); qDBusRegisterMetaType<QVector<QDBusUnixFileDescriptor> >();
#endif #endif
initialized.store(true); initialized.storeRelaxed(true);
} }
} }

View File

@ -473,7 +473,7 @@ QDBusPendingCall QDBusPendingCall::fromCompletedCall(const QDBusMessage &msg)
msg.type() == QDBusMessage::ReplyMessage) { msg.type() == QDBusMessage::ReplyMessage) {
d = new QDBusPendingCallPrivate(QDBusMessage(), 0); d = new QDBusPendingCallPrivate(QDBusMessage(), 0);
d->replyMessage = msg; d->replyMessage = msg;
d->ref.store(1); d->ref.storeRelaxed(1);
} }
return QDBusPendingCall(d); return QDBusPendingCall(d);

View File

@ -117,7 +117,7 @@ QDBusServer::~QDBusServer()
d->serverConnectionNames.clear(); d->serverConnectionNames.clear();
} }
d->serverObject = nullptr; d->serverObject = nullptr;
d->ref.store(0); d->ref.storeRelaxed(0);
d->deleteLater(); d->deleteLater();
} }

View File

@ -208,7 +208,7 @@ QDBusUnixFileDescriptor::~QDBusUnixFileDescriptor()
*/ */
bool QDBusUnixFileDescriptor::isValid() const bool QDBusUnixFileDescriptor::isValid() const
{ {
return d ? d->fd.load() != -1 : false; return d ? d->fd.loadRelaxed() != -1 : false;
} }
/*! /*!
@ -226,7 +226,7 @@ bool QDBusUnixFileDescriptor::isValid() const
*/ */
int QDBusUnixFileDescriptor::fileDescriptor() const int QDBusUnixFileDescriptor::fileDescriptor() const
{ {
return d ? d->fd.load() : -1; return d ? d->fd.loadRelaxed() : -1;
} }
// actual implementation // actual implementation
@ -283,12 +283,12 @@ void QDBusUnixFileDescriptor::giveFileDescriptor(int fileDescriptor)
else else
d = new QDBusUnixFileDescriptorPrivate; d = new QDBusUnixFileDescriptorPrivate;
const int fdl = d->fd.load(); const int fdl = d->fd.loadRelaxed();
if (fdl != -1) if (fdl != -1)
qt_safe_close(fdl); qt_safe_close(fdl);
if (fileDescriptor != -1) if (fileDescriptor != -1)
d->fd.store(fileDescriptor); d->fd.storeRelaxed(fileDescriptor);
} }
/*! /*!
@ -309,7 +309,7 @@ int QDBusUnixFileDescriptor::takeFileDescriptor()
QDBusUnixFileDescriptorPrivate::~QDBusUnixFileDescriptorPrivate() QDBusUnixFileDescriptorPrivate::~QDBusUnixFileDescriptorPrivate()
{ {
const int fdl = fd.load(); const int fdl = fd.loadRelaxed();
if (fdl != -1) if (fdl != -1)
qt_safe_close(fdl); qt_safe_close(fdl);
} }

View File

@ -987,7 +987,7 @@ bool QIcon::isNull() const
*/ */
bool QIcon::isDetached() const bool QIcon::isDetached() const
{ {
return !d || d->ref.load() == 1; return !d || d->ref.loadRelaxed() == 1;
} }
/*! \internal /*! \internal
@ -1000,7 +1000,7 @@ void QIcon::detach()
delete d; delete d;
d = 0; d = 0;
return; return;
} else if (d->ref.load() != 1) { } else if (d->ref.loadRelaxed() != 1) {
QIconPrivate *x = new QIconPrivate(d->engine->clone()); QIconPrivate *x = new QIconPrivate(d->engine->clone());
if (!d->ref.deref()) if (!d->ref.deref())
delete d; delete d;

View File

@ -1082,10 +1082,10 @@ QImage::operator QVariant() const
void QImage::detach() void QImage::detach()
{ {
if (d) { if (d) {
if (d->is_cached && d->ref.load() == 1) if (d->is_cached && d->ref.loadRelaxed() == 1)
QImagePixmapCleanupHooks::executeImageHooks(cacheKey()); QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
if (d->ref.load() != 1 || d->ro_data) if (d->ref.loadRelaxed() != 1 || d->ro_data)
*this = copy(); *this = copy();
if (d) if (d)
@ -4422,7 +4422,7 @@ qint64 QImage::cacheKey() const
bool QImage::isDetached() const bool QImage::isDetached() const
{ {
return d && d->ref.load() == 1; return d && d->ref.loadRelaxed() == 1;
} }
@ -5087,7 +5087,7 @@ bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFla
return true; return true;
// No in-place conversion if we have to detach // No in-place conversion if we have to detach
if (ref.load() > 1 || !own_data) if (ref.loadRelaxed() > 1 || !own_data)
return false; return false;
InPlace_Image_Converter converter = qimage_inplace_converter_map[format][newFormat]; InPlace_Image_Converter converter = qimage_inplace_converter_map[format][newFormat];

View File

@ -235,7 +235,7 @@ void QPicture::detach()
bool QPicture::isDetached() const bool QPicture::isDetached() const
{ {
return d_func()->ref.load() == 1; return d_func()->ref.loadRelaxed() == 1;
} }
/*! /*!

View File

@ -262,7 +262,7 @@ QPixmap::QPixmap(const char * const xpm[])
QPixmap::~QPixmap() QPixmap::~QPixmap()
{ {
Q_ASSERT(!data || data->ref.load() >= 1); // Catch if ref-counting changes again Q_ASSERT(!data || data->ref.loadRelaxed() >= 1); // Catch if ref-counting changes again
} }
/*! /*!
@ -910,7 +910,7 @@ void QPixmap::fill(const QColor &color)
return; return;
} }
if (data->ref.load() == 1) { if (data->ref.loadRelaxed() == 1) {
// detach() will also remove this pixmap from caches, so // detach() will also remove this pixmap from caches, so
// it has to be called even when ref == 1. // it has to be called even when ref == 1.
detach(); detach();
@ -1053,7 +1053,7 @@ QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap)
bool QPixmap::isDetached() const bool QPixmap::isDetached() const
{ {
return data && data->ref.load() == 1; return data && data->ref.loadRelaxed() == 1;
} }
/*! /*!
@ -1523,10 +1523,10 @@ void QPixmap::detach()
rasterData->image.detach(); rasterData->image.detach();
} }
if (data->is_cached && data->ref.load() == 1) if (data->is_cached && data->ref.loadRelaxed() == 1)
QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(data.data()); QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(data.data());
if (data->ref.load() != 1) { if (data->ref.loadRelaxed() != 1) {
*this = copy(); *this = copy();
} }
++data->detach_no; ++data->detach_no;

View File

@ -4921,7 +4921,7 @@ QVector<QPointF> QTouchEvent::TouchPoint::rawScreenPositions() const
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setId(int id) void QTouchEvent::TouchPoint::setId(int id)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->id = id; d->id = id;
} }
@ -4929,7 +4929,7 @@ void QTouchEvent::TouchPoint::setId(int id)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setUniqueId(qint64 uid) void QTouchEvent::TouchPoint::setUniqueId(qint64 uid)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->uniqueId = QPointingDeviceUniqueId::fromNumericId(uid); d->uniqueId = QPointingDeviceUniqueId::fromNumericId(uid);
} }
@ -4937,7 +4937,7 @@ void QTouchEvent::TouchPoint::setUniqueId(qint64 uid)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state) void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->state = state; d->state = state;
} }
@ -4945,7 +4945,7 @@ void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setPos(const QPointF &pos) void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->pos = pos; d->pos = pos;
} }
@ -4953,7 +4953,7 @@ void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos) void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->scenePos = scenePos; d->scenePos = scenePos;
} }
@ -4961,7 +4961,7 @@ void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos) void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->screenPos = screenPos; d->screenPos = screenPos;
} }
@ -4969,7 +4969,7 @@ void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos) void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->normalizedPos = normalizedPos; d->normalizedPos = normalizedPos;
} }
@ -4977,7 +4977,7 @@ void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos) void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->startPos = startPos; d->startPos = startPos;
} }
@ -4985,7 +4985,7 @@ void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos) void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->startScenePos = startScenePos; d->startScenePos = startScenePos;
} }
@ -4993,7 +4993,7 @@ void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos) void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->startScreenPos = startScreenPos; d->startScreenPos = startScreenPos;
} }
@ -5001,7 +5001,7 @@ void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos) void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->startNormalizedPos = startNormalizedPos; d->startNormalizedPos = startNormalizedPos;
} }
@ -5009,7 +5009,7 @@ void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormaliz
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos) void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->lastPos = lastPos; d->lastPos = lastPos;
} }
@ -5017,7 +5017,7 @@ void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos) void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->lastScenePos = lastScenePos; d->lastScenePos = lastScenePos;
} }
@ -5025,7 +5025,7 @@ void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos) void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->lastScreenPos = lastScreenPos; d->lastScreenPos = lastScreenPos;
} }
@ -5033,7 +5033,7 @@ void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos) void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->lastNormalizedPos = lastNormalizedPos; d->lastNormalizedPos = lastNormalizedPos;
} }
@ -5044,7 +5044,7 @@ void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalized
*/ */
void QTouchEvent::TouchPoint::setRect(const QRectF &rect) void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->pos = rect.center(); d->pos = rect.center();
d->ellipseDiameters = rect.size(); d->ellipseDiameters = rect.size();
@ -5055,7 +5055,7 @@ void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
*/ */
void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect) void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->scenePos = sceneRect.center(); d->scenePos = sceneRect.center();
d->ellipseDiameters = sceneRect.size(); d->ellipseDiameters = sceneRect.size();
@ -5066,7 +5066,7 @@ void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect)
*/ */
void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect) void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->screenPos = screenRect.center(); d->screenPos = screenRect.center();
d->ellipseDiameters = screenRect.size(); d->ellipseDiameters = screenRect.size();
@ -5075,7 +5075,7 @@ void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setPressure(qreal pressure) void QTouchEvent::TouchPoint::setPressure(qreal pressure)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->pressure = pressure; d->pressure = pressure;
} }
@ -5083,7 +5083,7 @@ void QTouchEvent::TouchPoint::setPressure(qreal pressure)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setRotation(qreal angle) void QTouchEvent::TouchPoint::setRotation(qreal angle)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->rotation = angle; d->rotation = angle;
} }
@ -5091,7 +5091,7 @@ void QTouchEvent::TouchPoint::setRotation(qreal angle)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &dia) void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &dia)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->ellipseDiameters = dia; d->ellipseDiameters = dia;
} }
@ -5099,7 +5099,7 @@ void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &dia)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v) void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->velocity = v; d->velocity = v;
} }
@ -5107,7 +5107,7 @@ void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v)
/*! \internal */ /*! \internal */
void QTouchEvent::TouchPoint::setRawScreenPositions(const QVector<QPointF> &positions) void QTouchEvent::TouchPoint::setRawScreenPositions(const QVector<QPointF> &positions)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->rawScreenPositions = positions; d->rawScreenPositions = positions;
} }
@ -5117,7 +5117,7 @@ void QTouchEvent::TouchPoint::setRawScreenPositions(const QVector<QPointF> &posi
*/ */
void QTouchEvent::TouchPoint::setFlags(InfoFlags flags) void QTouchEvent::TouchPoint::setFlags(InfoFlags flags)
{ {
if (d->ref.load() != 1) if (d->ref.loadRelaxed() != 1)
d = d->detach(); d = d->detach();
d->flags = flags; d->flags = flags;
} }

View File

@ -73,7 +73,7 @@ public:
inline QTouchEventTouchPointPrivate *detach() inline QTouchEventTouchPointPrivate *detach()
{ {
QTouchEventTouchPointPrivate *d = new QTouchEventTouchPointPrivate(*this); QTouchEventTouchPointPrivate *d = new QTouchEventTouchPointPrivate(*this);
d->ref.store(1); d->ref.storeRelaxed(1);
if (!this->ref.deref()) if (!this->ref.deref())
delete this; delete this;
return d; return d;

View File

@ -114,7 +114,7 @@ public:
static QAbstractEventDispatcher *qt_qpa_core_dispatcher() static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
{ {
if (QCoreApplication::instance()) if (QCoreApplication::instance())
return QCoreApplication::instance()->d_func()->threadData->eventDispatcher.load(); return QCoreApplication::instance()->d_func()->threadData->eventDispatcher.loadRelaxed();
else else
return nullptr; return nullptr;
} }

View File

@ -1518,7 +1518,7 @@ bool QKeySequence::operator< (const QKeySequence &other) const
*/ */
bool QKeySequence::isDetached() const bool QKeySequence::isDetached() const
{ {
return d->ref.load() == 1; return d->ref.loadRelaxed() == 1;
} }
/*! /*!

View File

@ -1634,7 +1634,7 @@ QOpenGLMultiGroupSharedResource::~QOpenGLMultiGroupSharedResource()
active.deref(); active.deref();
} }
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
if (active.load() != 0) { if (active.loadRelaxed() != 0) {
qWarning("QtGui: Resources are still available at program shutdown.\n" qWarning("QtGui: Resources are still available at program shutdown.\n"
" This is possibly caused by a leaked QOpenGLWidget, \n" " This is possibly caused by a leaked QOpenGLWidget, \n"
" QOpenGLFramebufferObject or QOpenGLPixelBuffer."); " QOpenGLFramebufferObject or QOpenGLPixelBuffer.");

View File

@ -830,7 +830,7 @@ bool QPalette::isBrushSet(ColorGroup cg, ColorRole cr) const
*/ */
void QPalette::detach() void QPalette::detach()
{ {
if (d->ref.load() != 1) { if (d->ref.loadRelaxed() != 1) {
QPalettePrivate *x = new QPalettePrivate; QPalettePrivate *x = new QPalettePrivate;
for(int grp = 0; grp < (int)NColorGroups; grp++) { for(int grp = 0; grp < (int)NColorGroups; grp++) {
for(int role = 0; role < (int)NColorRoles; role++) for(int role = 0; role < (int)NColorRoles; role++)

View File

@ -246,7 +246,7 @@ QSurfaceFormat::QSurfaceFormat(QSurfaceFormat::FormatOptions options) :
*/ */
void QSurfaceFormat::detach() void QSurfaceFormat::detach()
{ {
if (d->ref.load() != 1) { if (d->ref.loadRelaxed() != 1) {
QSurfaceFormatPrivate *newd = new QSurfaceFormatPrivate(d); QSurfaceFormatPrivate *newd = new QSurfaceFormatPrivate(d);
if (!d->ref.deref()) if (!d->ref.deref())
delete d; delete d;

View File

@ -1115,7 +1115,7 @@ bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFl
} else { } else {
sendWindowSystemEvents(flags); sendWindowSystemEvents(flags);
} }
return QWindowSystemInterfacePrivate::eventAccepted.load() > 0; return QWindowSystemInterfacePrivate::eventAccepted.loadRelaxed() > 0;
} }
void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags) void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
@ -1156,7 +1156,7 @@ bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFla
// (excluding flush events). This state can then be // (excluding flush events). This state can then be
// returned by flushWindowSystemEvents(). // returned by flushWindowSystemEvents().
if (event->type != QWindowSystemInterfacePrivate::FlushEvents) if (event->type != QWindowSystemInterfacePrivate::FlushEvents)
QWindowSystemInterfacePrivate::eventAccepted.store(event->eventAccepted); QWindowSystemInterfacePrivate::eventAccepted.storeRelaxed(event->eventAccepted);
delete event; delete event;
} }

View File

@ -183,7 +183,7 @@ QT_BEGIN_NAMESPACE
*/ */
void QOpenGLFramebufferObjectFormat::detach() void QOpenGLFramebufferObjectFormat::detach()
{ {
if (d->ref.load() != 1) { if (d->ref.loadRelaxed() != 1) {
QOpenGLFramebufferObjectFormatPrivate *newd QOpenGLFramebufferObjectFormatPrivate *newd
= new QOpenGLFramebufferObjectFormatPrivate(d); = new QOpenGLFramebufferObjectFormatPrivate(d);
if (!d->ref.deref()) if (!d->ref.deref())

View File

@ -76,11 +76,11 @@ QOpenGLFunctions_1_0::~QOpenGLFunctions_1_0()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -78,19 +78,19 @@ QOpenGLFunctions_1_1::~QOpenGLFunctions_1_1()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -80,27 +80,27 @@ QOpenGLFunctions_1_2::~QOpenGLFunctions_1_2()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
if (d_1_2_Deprecated) { if (d_1_2_Deprecated) {
d_1_2_Deprecated->refs.deref(); d_1_2_Deprecated->refs.deref();
Q_ASSERT(d_1_2_Deprecated->refs.load()); Q_ASSERT(d_1_2_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -82,35 +82,35 @@ QOpenGLFunctions_1_3::~QOpenGLFunctions_1_3()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
if (d_1_2_Deprecated) { if (d_1_2_Deprecated) {
d_1_2_Deprecated->refs.deref(); d_1_2_Deprecated->refs.deref();
Q_ASSERT(d_1_2_Deprecated->refs.load()); Q_ASSERT(d_1_2_Deprecated->refs.loadRelaxed());
} }
if (d_1_3_Deprecated) { if (d_1_3_Deprecated) {
d_1_3_Deprecated->refs.deref(); d_1_3_Deprecated->refs.deref();
Q_ASSERT(d_1_3_Deprecated->refs.load()); Q_ASSERT(d_1_3_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -84,43 +84,43 @@ QOpenGLFunctions_1_4::~QOpenGLFunctions_1_4()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_4_Core) { if (d_1_4_Core) {
d_1_4_Core->refs.deref(); d_1_4_Core->refs.deref();
Q_ASSERT(d_1_4_Core->refs.load()); Q_ASSERT(d_1_4_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
if (d_1_2_Deprecated) { if (d_1_2_Deprecated) {
d_1_2_Deprecated->refs.deref(); d_1_2_Deprecated->refs.deref();
Q_ASSERT(d_1_2_Deprecated->refs.load()); Q_ASSERT(d_1_2_Deprecated->refs.loadRelaxed());
} }
if (d_1_3_Deprecated) { if (d_1_3_Deprecated) {
d_1_3_Deprecated->refs.deref(); d_1_3_Deprecated->refs.deref();
Q_ASSERT(d_1_3_Deprecated->refs.load()); Q_ASSERT(d_1_3_Deprecated->refs.loadRelaxed());
} }
if (d_1_4_Deprecated) { if (d_1_4_Deprecated) {
d_1_4_Deprecated->refs.deref(); d_1_4_Deprecated->refs.deref();
Q_ASSERT(d_1_4_Deprecated->refs.load()); Q_ASSERT(d_1_4_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -85,47 +85,47 @@ QOpenGLFunctions_1_5::~QOpenGLFunctions_1_5()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_4_Core) { if (d_1_4_Core) {
d_1_4_Core->refs.deref(); d_1_4_Core->refs.deref();
Q_ASSERT(d_1_4_Core->refs.load()); Q_ASSERT(d_1_4_Core->refs.loadRelaxed());
} }
if (d_1_5_Core) { if (d_1_5_Core) {
d_1_5_Core->refs.deref(); d_1_5_Core->refs.deref();
Q_ASSERT(d_1_5_Core->refs.load()); Q_ASSERT(d_1_5_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
if (d_1_2_Deprecated) { if (d_1_2_Deprecated) {
d_1_2_Deprecated->refs.deref(); d_1_2_Deprecated->refs.deref();
Q_ASSERT(d_1_2_Deprecated->refs.load()); Q_ASSERT(d_1_2_Deprecated->refs.loadRelaxed());
} }
if (d_1_3_Deprecated) { if (d_1_3_Deprecated) {
d_1_3_Deprecated->refs.deref(); d_1_3_Deprecated->refs.deref();
Q_ASSERT(d_1_3_Deprecated->refs.load()); Q_ASSERT(d_1_3_Deprecated->refs.loadRelaxed());
} }
if (d_1_4_Deprecated) { if (d_1_4_Deprecated) {
d_1_4_Deprecated->refs.deref(); d_1_4_Deprecated->refs.deref();
Q_ASSERT(d_1_4_Deprecated->refs.load()); Q_ASSERT(d_1_4_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -87,51 +87,51 @@ QOpenGLFunctions_2_0::~QOpenGLFunctions_2_0()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_4_Core) { if (d_1_4_Core) {
d_1_4_Core->refs.deref(); d_1_4_Core->refs.deref();
Q_ASSERT(d_1_4_Core->refs.load()); Q_ASSERT(d_1_4_Core->refs.loadRelaxed());
} }
if (d_1_5_Core) { if (d_1_5_Core) {
d_1_5_Core->refs.deref(); d_1_5_Core->refs.deref();
Q_ASSERT(d_1_5_Core->refs.load()); Q_ASSERT(d_1_5_Core->refs.loadRelaxed());
} }
if (d_2_0_Core) { if (d_2_0_Core) {
d_2_0_Core->refs.deref(); d_2_0_Core->refs.deref();
Q_ASSERT(d_2_0_Core->refs.load()); Q_ASSERT(d_2_0_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
if (d_1_2_Deprecated) { if (d_1_2_Deprecated) {
d_1_2_Deprecated->refs.deref(); d_1_2_Deprecated->refs.deref();
Q_ASSERT(d_1_2_Deprecated->refs.load()); Q_ASSERT(d_1_2_Deprecated->refs.loadRelaxed());
} }
if (d_1_3_Deprecated) { if (d_1_3_Deprecated) {
d_1_3_Deprecated->refs.deref(); d_1_3_Deprecated->refs.deref();
Q_ASSERT(d_1_3_Deprecated->refs.load()); Q_ASSERT(d_1_3_Deprecated->refs.loadRelaxed());
} }
if (d_1_4_Deprecated) { if (d_1_4_Deprecated) {
d_1_4_Deprecated->refs.deref(); d_1_4_Deprecated->refs.deref();
Q_ASSERT(d_1_4_Deprecated->refs.load()); Q_ASSERT(d_1_4_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -88,55 +88,55 @@ QOpenGLFunctions_2_1::~QOpenGLFunctions_2_1()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_4_Core) { if (d_1_4_Core) {
d_1_4_Core->refs.deref(); d_1_4_Core->refs.deref();
Q_ASSERT(d_1_4_Core->refs.load()); Q_ASSERT(d_1_4_Core->refs.loadRelaxed());
} }
if (d_1_5_Core) { if (d_1_5_Core) {
d_1_5_Core->refs.deref(); d_1_5_Core->refs.deref();
Q_ASSERT(d_1_5_Core->refs.load()); Q_ASSERT(d_1_5_Core->refs.loadRelaxed());
} }
if (d_2_0_Core) { if (d_2_0_Core) {
d_2_0_Core->refs.deref(); d_2_0_Core->refs.deref();
Q_ASSERT(d_2_0_Core->refs.load()); Q_ASSERT(d_2_0_Core->refs.loadRelaxed());
} }
if (d_2_1_Core) { if (d_2_1_Core) {
d_2_1_Core->refs.deref(); d_2_1_Core->refs.deref();
Q_ASSERT(d_2_1_Core->refs.load()); Q_ASSERT(d_2_1_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
if (d_1_2_Deprecated) { if (d_1_2_Deprecated) {
d_1_2_Deprecated->refs.deref(); d_1_2_Deprecated->refs.deref();
Q_ASSERT(d_1_2_Deprecated->refs.load()); Q_ASSERT(d_1_2_Deprecated->refs.loadRelaxed());
} }
if (d_1_3_Deprecated) { if (d_1_3_Deprecated) {
d_1_3_Deprecated->refs.deref(); d_1_3_Deprecated->refs.deref();
Q_ASSERT(d_1_3_Deprecated->refs.load()); Q_ASSERT(d_1_3_Deprecated->refs.loadRelaxed());
} }
if (d_1_4_Deprecated) { if (d_1_4_Deprecated) {
d_1_4_Deprecated->refs.deref(); d_1_4_Deprecated->refs.deref();
Q_ASSERT(d_1_4_Deprecated->refs.load()); Q_ASSERT(d_1_4_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -90,59 +90,59 @@ QOpenGLFunctions_3_0::~QOpenGLFunctions_3_0()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_4_Core) { if (d_1_4_Core) {
d_1_4_Core->refs.deref(); d_1_4_Core->refs.deref();
Q_ASSERT(d_1_4_Core->refs.load()); Q_ASSERT(d_1_4_Core->refs.loadRelaxed());
} }
if (d_1_5_Core) { if (d_1_5_Core) {
d_1_5_Core->refs.deref(); d_1_5_Core->refs.deref();
Q_ASSERT(d_1_5_Core->refs.load()); Q_ASSERT(d_1_5_Core->refs.loadRelaxed());
} }
if (d_2_0_Core) { if (d_2_0_Core) {
d_2_0_Core->refs.deref(); d_2_0_Core->refs.deref();
Q_ASSERT(d_2_0_Core->refs.load()); Q_ASSERT(d_2_0_Core->refs.loadRelaxed());
} }
if (d_2_1_Core) { if (d_2_1_Core) {
d_2_1_Core->refs.deref(); d_2_1_Core->refs.deref();
Q_ASSERT(d_2_1_Core->refs.load()); Q_ASSERT(d_2_1_Core->refs.loadRelaxed());
} }
if (d_3_0_Core) { if (d_3_0_Core) {
d_3_0_Core->refs.deref(); d_3_0_Core->refs.deref();
Q_ASSERT(d_3_0_Core->refs.load()); Q_ASSERT(d_3_0_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
if (d_1_2_Deprecated) { if (d_1_2_Deprecated) {
d_1_2_Deprecated->refs.deref(); d_1_2_Deprecated->refs.deref();
Q_ASSERT(d_1_2_Deprecated->refs.load()); Q_ASSERT(d_1_2_Deprecated->refs.loadRelaxed());
} }
if (d_1_3_Deprecated) { if (d_1_3_Deprecated) {
d_1_3_Deprecated->refs.deref(); d_1_3_Deprecated->refs.deref();
Q_ASSERT(d_1_3_Deprecated->refs.load()); Q_ASSERT(d_1_3_Deprecated->refs.loadRelaxed());
} }
if (d_1_4_Deprecated) { if (d_1_4_Deprecated) {
d_1_4_Deprecated->refs.deref(); d_1_4_Deprecated->refs.deref();
Q_ASSERT(d_1_4_Deprecated->refs.load()); Q_ASSERT(d_1_4_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -84,43 +84,43 @@ QOpenGLFunctions_3_1::~QOpenGLFunctions_3_1()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_4_Core) { if (d_1_4_Core) {
d_1_4_Core->refs.deref(); d_1_4_Core->refs.deref();
Q_ASSERT(d_1_4_Core->refs.load()); Q_ASSERT(d_1_4_Core->refs.loadRelaxed());
} }
if (d_1_5_Core) { if (d_1_5_Core) {
d_1_5_Core->refs.deref(); d_1_5_Core->refs.deref();
Q_ASSERT(d_1_5_Core->refs.load()); Q_ASSERT(d_1_5_Core->refs.loadRelaxed());
} }
if (d_2_0_Core) { if (d_2_0_Core) {
d_2_0_Core->refs.deref(); d_2_0_Core->refs.deref();
Q_ASSERT(d_2_0_Core->refs.load()); Q_ASSERT(d_2_0_Core->refs.loadRelaxed());
} }
if (d_2_1_Core) { if (d_2_1_Core) {
d_2_1_Core->refs.deref(); d_2_1_Core->refs.deref();
Q_ASSERT(d_2_1_Core->refs.load()); Q_ASSERT(d_2_1_Core->refs.loadRelaxed());
} }
if (d_3_0_Core) { if (d_3_0_Core) {
d_3_0_Core->refs.deref(); d_3_0_Core->refs.deref();
Q_ASSERT(d_3_0_Core->refs.load()); Q_ASSERT(d_3_0_Core->refs.loadRelaxed());
} }
if (d_3_1_Core) { if (d_3_1_Core) {
d_3_1_Core->refs.deref(); d_3_1_Core->refs.deref();
Q_ASSERT(d_3_1_Core->refs.load()); Q_ASSERT(d_3_1_Core->refs.loadRelaxed());
} }
} }

View File

@ -92,67 +92,67 @@ QOpenGLFunctions_3_2_Compatibility::~QOpenGLFunctions_3_2_Compatibility()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_4_Core) { if (d_1_4_Core) {
d_1_4_Core->refs.deref(); d_1_4_Core->refs.deref();
Q_ASSERT(d_1_4_Core->refs.load()); Q_ASSERT(d_1_4_Core->refs.loadRelaxed());
} }
if (d_1_5_Core) { if (d_1_5_Core) {
d_1_5_Core->refs.deref(); d_1_5_Core->refs.deref();
Q_ASSERT(d_1_5_Core->refs.load()); Q_ASSERT(d_1_5_Core->refs.loadRelaxed());
} }
if (d_2_0_Core) { if (d_2_0_Core) {
d_2_0_Core->refs.deref(); d_2_0_Core->refs.deref();
Q_ASSERT(d_2_0_Core->refs.load()); Q_ASSERT(d_2_0_Core->refs.loadRelaxed());
} }
if (d_2_1_Core) { if (d_2_1_Core) {
d_2_1_Core->refs.deref(); d_2_1_Core->refs.deref();
Q_ASSERT(d_2_1_Core->refs.load()); Q_ASSERT(d_2_1_Core->refs.loadRelaxed());
} }
if (d_3_0_Core) { if (d_3_0_Core) {
d_3_0_Core->refs.deref(); d_3_0_Core->refs.deref();
Q_ASSERT(d_3_0_Core->refs.load()); Q_ASSERT(d_3_0_Core->refs.loadRelaxed());
} }
if (d_3_1_Core) { if (d_3_1_Core) {
d_3_1_Core->refs.deref(); d_3_1_Core->refs.deref();
Q_ASSERT(d_3_1_Core->refs.load()); Q_ASSERT(d_3_1_Core->refs.loadRelaxed());
} }
if (d_3_2_Core) { if (d_3_2_Core) {
d_3_2_Core->refs.deref(); d_3_2_Core->refs.deref();
Q_ASSERT(d_3_2_Core->refs.load()); Q_ASSERT(d_3_2_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
if (d_1_2_Deprecated) { if (d_1_2_Deprecated) {
d_1_2_Deprecated->refs.deref(); d_1_2_Deprecated->refs.deref();
Q_ASSERT(d_1_2_Deprecated->refs.load()); Q_ASSERT(d_1_2_Deprecated->refs.loadRelaxed());
} }
if (d_1_3_Deprecated) { if (d_1_3_Deprecated) {
d_1_3_Deprecated->refs.deref(); d_1_3_Deprecated->refs.deref();
Q_ASSERT(d_1_3_Deprecated->refs.load()); Q_ASSERT(d_1_3_Deprecated->refs.loadRelaxed());
} }
if (d_1_4_Deprecated) { if (d_1_4_Deprecated) {
d_1_4_Deprecated->refs.deref(); d_1_4_Deprecated->refs.deref();
Q_ASSERT(d_1_4_Deprecated->refs.load()); Q_ASSERT(d_1_4_Deprecated->refs.loadRelaxed());
} }
} }

View File

@ -85,47 +85,47 @@ QOpenGLFunctions_3_2_Core::~QOpenGLFunctions_3_2_Core()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_4_Core) { if (d_1_4_Core) {
d_1_4_Core->refs.deref(); d_1_4_Core->refs.deref();
Q_ASSERT(d_1_4_Core->refs.load()); Q_ASSERT(d_1_4_Core->refs.loadRelaxed());
} }
if (d_1_5_Core) { if (d_1_5_Core) {
d_1_5_Core->refs.deref(); d_1_5_Core->refs.deref();
Q_ASSERT(d_1_5_Core->refs.load()); Q_ASSERT(d_1_5_Core->refs.loadRelaxed());
} }
if (d_2_0_Core) { if (d_2_0_Core) {
d_2_0_Core->refs.deref(); d_2_0_Core->refs.deref();
Q_ASSERT(d_2_0_Core->refs.load()); Q_ASSERT(d_2_0_Core->refs.loadRelaxed());
} }
if (d_2_1_Core) { if (d_2_1_Core) {
d_2_1_Core->refs.deref(); d_2_1_Core->refs.deref();
Q_ASSERT(d_2_1_Core->refs.load()); Q_ASSERT(d_2_1_Core->refs.loadRelaxed());
} }
if (d_3_0_Core) { if (d_3_0_Core) {
d_3_0_Core->refs.deref(); d_3_0_Core->refs.deref();
Q_ASSERT(d_3_0_Core->refs.load()); Q_ASSERT(d_3_0_Core->refs.loadRelaxed());
} }
if (d_3_1_Core) { if (d_3_1_Core) {
d_3_1_Core->refs.deref(); d_3_1_Core->refs.deref();
Q_ASSERT(d_3_1_Core->refs.load()); Q_ASSERT(d_3_1_Core->refs.loadRelaxed());
} }
if (d_3_2_Core) { if (d_3_2_Core) {
d_3_2_Core->refs.deref(); d_3_2_Core->refs.deref();
Q_ASSERT(d_3_2_Core->refs.load()); Q_ASSERT(d_3_2_Core->refs.loadRelaxed());
} }
} }

View File

@ -93,75 +93,75 @@ QOpenGLFunctions_3_3_Compatibility::~QOpenGLFunctions_3_3_Compatibility()
{ {
if (d_1_0_Core) { if (d_1_0_Core) {
d_1_0_Core->refs.deref(); d_1_0_Core->refs.deref();
Q_ASSERT(d_1_0_Core->refs.load()); Q_ASSERT(d_1_0_Core->refs.loadRelaxed());
} }
if (d_1_1_Core) { if (d_1_1_Core) {
d_1_1_Core->refs.deref(); d_1_1_Core->refs.deref();
Q_ASSERT(d_1_1_Core->refs.load()); Q_ASSERT(d_1_1_Core->refs.loadRelaxed());
} }
if (d_1_2_Core) { if (d_1_2_Core) {
d_1_2_Core->refs.deref(); d_1_2_Core->refs.deref();
Q_ASSERT(d_1_2_Core->refs.load()); Q_ASSERT(d_1_2_Core->refs.loadRelaxed());
} }
if (d_1_3_Core) { if (d_1_3_Core) {
d_1_3_Core->refs.deref(); d_1_3_Core->refs.deref();
Q_ASSERT(d_1_3_Core->refs.load()); Q_ASSERT(d_1_3_Core->refs.loadRelaxed());
} }
if (d_1_4_Core) { if (d_1_4_Core) {
d_1_4_Core->refs.deref(); d_1_4_Core->refs.deref();
Q_ASSERT(d_1_4_Core->refs.load()); Q_ASSERT(d_1_4_Core->refs.loadRelaxed());
} }
if (d_1_5_Core) { if (d_1_5_Core) {
d_1_5_Core->refs.deref(); d_1_5_Core->refs.deref();
Q_ASSERT(d_1_5_Core->refs.load()); Q_ASSERT(d_1_5_Core->refs.loadRelaxed());
} }
if (d_2_0_Core) { if (d_2_0_Core) {
d_2_0_Core->refs.deref(); d_2_0_Core->refs.deref();
Q_ASSERT(d_2_0_Core->refs.load()); Q_ASSERT(d_2_0_Core->refs.loadRelaxed());
} }
if (d_2_1_Core) { if (d_2_1_Core) {
d_2_1_Core->refs.deref(); d_2_1_Core->refs.deref();
Q_ASSERT(d_2_1_Core->refs.load()); Q_ASSERT(d_2_1_Core->refs.loadRelaxed());
} }
if (d_3_0_Core) { if (d_3_0_Core) {
d_3_0_Core->refs.deref(); d_3_0_Core->refs.deref();
Q_ASSERT(d_3_0_Core->refs.load()); Q_ASSERT(d_3_0_Core->refs.loadRelaxed());
} }
if (d_3_1_Core) { if (d_3_1_Core) {
d_3_1_Core->refs.deref(); d_3_1_Core->refs.deref();
Q_ASSERT(d_3_1_Core->refs.load()); Q_ASSERT(d_3_1_Core->refs.loadRelaxed());
} }
if (d_3_2_Core) { if (d_3_2_Core) {
d_3_2_Core->refs.deref(); d_3_2_Core->refs.deref();
Q_ASSERT(d_3_2_Core->refs.load()); Q_ASSERT(d_3_2_Core->refs.loadRelaxed());
} }
if (d_3_3_Core) { if (d_3_3_Core) {
d_3_3_Core->refs.deref(); d_3_3_Core->refs.deref();
Q_ASSERT(d_3_3_Core->refs.load()); Q_ASSERT(d_3_3_Core->refs.loadRelaxed());
} }
if (d_1_0_Deprecated) { if (d_1_0_Deprecated) {
d_1_0_Deprecated->refs.deref(); d_1_0_Deprecated->refs.deref();
Q_ASSERT(d_1_0_Deprecated->refs.load()); Q_ASSERT(d_1_0_Deprecated->refs.loadRelaxed());
} }
if (d_1_1_Deprecated) { if (d_1_1_Deprecated) {
d_1_1_Deprecated->refs.deref(); d_1_1_Deprecated->refs.deref();
Q_ASSERT(d_1_1_Deprecated->refs.load()); Q_ASSERT(d_1_1_Deprecated->refs.loadRelaxed());
} }
if (d_1_2_Deprecated) { if (d_1_2_Deprecated) {
d_1_2_Deprecated->refs.deref(); d_1_2_Deprecated->refs.deref();
Q_ASSERT(d_1_2_Deprecated->refs.load()); Q_ASSERT(d_1_2_Deprecated->refs.loadRelaxed());
} }
if (d_1_3_Deprecated) { if (d_1_3_Deprecated) {
d_1_3_Deprecated->refs.deref(); d_1_3_Deprecated->refs.deref();
Q_ASSERT(d_1_3_Deprecated->refs.load()); Q_ASSERT(d_1_3_Deprecated->refs.loadRelaxed());
} }
if (d_1_4_Deprecated) { if (d_1_4_Deprecated) {
d_1_4_Deprecated->refs.deref(); d_1_4_Deprecated->refs.deref();
Q_ASSERT(d_1_4_Deprecated->refs.load()); Q_ASSERT(d_1_4_Deprecated->refs.loadRelaxed());
} }
if (d_3_3_Deprecated) { if (d_3_3_Deprecated) {
d_3_3_Deprecated->refs.deref(); d_3_3_Deprecated->refs.deref();
Q_ASSERT(d_3_3_Deprecated->refs.load()); Q_ASSERT(d_3_3_Deprecated->refs.loadRelaxed());
} }
} }

Some files were not shown because too many files have changed in this diff Show More