diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp index a54caa878bb..efbcf9ce583 100644 --- a/src/corelib/thread/qfutureinterface.cpp +++ b/src/corelib/thread/qfutureinterface.cpp @@ -43,12 +43,9 @@ #include #include +#include // for qYieldCpu() #include -#ifdef Q_PROCESSOR_X86 -# include // for _mm_pause() -#endif - #ifdef interface # undef interface #endif @@ -108,17 +105,11 @@ static inline int switch_off(QAtomicInt &a, int which) static inline int switch_from_to(QAtomicInt &a, int from, int to) { - int newValue; - int expected = a.loadRelaxed(); - for (;;) { - newValue = (expected & ~from) | to; - if (a.testAndSetRelaxed(expected, newValue, expected)) - break; -#ifdef Q_PROCESSOR_X86 - _mm_pause(); -#endif - } - return newValue; + const auto adjusted = [&](int old) { return (old & ~from) | to; }; + int value = a.loadRelaxed(); + while (!a.testAndSetRelaxed(value, adjusted(value), value)) + qYieldCpu(); + return value; } void QFutureInterfaceBase::cancel()