summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-03-25 13:58:00 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2021-04-06 09:55:14 +0100
commit9211d04730da7495fd2584e6768b73c3f86aba00 (patch)
treed123064b77bc9ec4d9c0bbe8cb3e77e286fd24bd /src/corelib/thread
parentc87847db8781a6846069e0f7e55b8ccc64d9420d (diff)
QSemaphore: move suspect increment of waiter count
We might return false a few lines down, without decreasing the count. Change-Id: I0a90c07f279860987e41539e9d5f3b5d2cb15207 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qsemaphore.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp
index ee4cee5281..5111d80ac6 100644
--- a/src/corelib/thread/qsemaphore.cpp
+++ b/src/corelib/thread/qsemaphore.cpp
@@ -246,13 +246,13 @@ template <bool IsTimed> bool futexSemaphoreTryAcquire(QBasicAtomicInteger<quintp
// we need to wait
quintptr oneWaiter = quintptr(Q_UINT64_C(1) << 32); // zero on 32-bit
if (futexHasWaiterCount) {
- // increase the waiter count
- u.fetchAndAddRelaxed(oneWaiter);
-
// We don't use the fetched value from above so futexWait() fails if
// it changed after the testAndSetOrdered above.
if ((quint64(curValue) >> 32) == 0x7fffffff)
return false; // overflow!
+
+ // increase the waiter count
+ u.fetchAndAddRelaxed(oneWaiter);
curValue += oneWaiter;
// Also adjust nn to subtract oneWaiter when we succeed in acquiring.