summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qsemaphore.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-06-10 09:47:25 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-06-15 04:04:56 -0700
commit96c76839f9870f44790bbd1936a96c0d5200b6ad (patch)
treea1230d73a78fa4da13ed193cfdc00d2ead173fd4 /src/corelib/thread/qsemaphore.cpp
parent585db639a407069c241e11351df1ed3d1e7b869e (diff)
Switch futex support to QDeadlineTimer
This allows us to use absolute times on Linux (today) and FreeBSD (soon), plus simplifies both QMutex and QSemaphore. Change-Id: I63b988479db546dabffcfffd17675a182aa528fa Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/thread/qsemaphore.cpp')
-rw-r--r--src/corelib/thread/qsemaphore.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp
index e09750581e..c472e62698 100644
--- a/src/corelib/thread/qsemaphore.cpp
+++ b/src/corelib/thread/qsemaphore.cpp
@@ -149,7 +149,6 @@ futexSemaphoreTryAcquire_loop(QBasicAtomicInteger<quintptr> &u, quintptr curValu
QDeadlineTimer timer)
{
using namespace std::chrono;
- nanoseconds remainingTime = IsTimed ? timer.remainingTimeAsDuration() : -1ns;
int n = int(unsigned(nn));
// we're called after one testAndSet, so start by waiting first
@@ -166,8 +165,8 @@ futexSemaphoreTryAcquire_loop(QBasicAtomicInteger<quintptr> &u, quintptr curValu
}
}
- if (IsTimed && remainingTime > 0ns) {
- bool timedout = !futexWait(*ptr, curValue, remainingTime);
+ if (IsTimed) {
+ bool timedout = !futexWait(*ptr, curValue, timer);
if (timedout)
return false;
} else {
@@ -175,8 +174,6 @@ futexSemaphoreTryAcquire_loop(QBasicAtomicInteger<quintptr> &u, quintptr curValu
}
curValue = u.loadAcquire();
- if (IsTimed)
- remainingTime = timer.remainingTimeAsDuration();
// try to acquire
while (futexAvailCounter(curValue) >= n) {
@@ -186,7 +183,7 @@ futexSemaphoreTryAcquire_loop(QBasicAtomicInteger<quintptr> &u, quintptr curValu
}
// not enough tokens available, put us to wait
- if (IsTimed && remainingTime == 0ns)
+ if (IsTimed && timer.hasExpired())
return false;
}
}