summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qsemaphore.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-06-30 07:17:47 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-06-30 23:48:21 +0200
commit38448b19a1c61cb5d5592e73efdbc4750bb835b2 (patch)
tree49951c2601895a82e32ef3b86261f6fc0933ba38 /src/corelib/thread/qsemaphore.cpp
parent6f27255cd40ea4bd12a27737096051e4fa9945b3 (diff)
QSemaphore: add <chrono> overload of tryAcquire()
... and C++20 std::counting_semaphore API compatibility. [ChangeLog][QtCore][QSemaphore] tryAcquire() now optionally takes a <chrono> duration as timeout, not just int milliseconds. [ChangeLog][QtCore][QSemaphore] Added try_acquire{,_for,_until}() for C++20 std::counting_semaphore compatibility. Change-Id: I34b6b4bf57a54745d4b97349903d090c4995338a Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/thread/qsemaphore.cpp')
-rw-r--r--src/corelib/thread/qsemaphore.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp
index dfc179486c..23fded1cc0 100644
--- a/src/corelib/thread/qsemaphore.cpp
+++ b/src/corelib/thread/qsemaphore.cpp
@@ -486,6 +486,46 @@ bool QSemaphore::tryAcquire(int n, int timeout)
}
/*!
+ \fn template <typename Rep, typename Period> QSemaphore::tryAcquire(int n, std::chrono::duration<Rep, Period> timeout)
+ \overload
+ \since 6.3
+*/
+
+/*!
+ \fn QSemaphore::try_acquire()
+ \since 6.3
+
+ This function is provided for \c{std::counting_semaphore} compatibility.
+
+ It is equivalent to calling \c{tryAcquire(1)}.
+
+ \sa tryAcquire(), try_acquire_for(), try_acquire_until()
+*/
+
+/*!
+ \fn template <typename Rep, typename Period> QSemaphore::try_acquire_for(std::chrono::duration<Rep, Period> timeout)
+ \since 6.3
+
+ This function is provided for \c{std::counting_semaphore} compatibility.
+
+ It is equivalent to calling \c{tryAcquire(1, timeout)}.
+
+ \sa tryAcquire(), try_acquire(), try_acquire_until()
+*/
+
+/*!
+ \fn template <typename Clock, typename Duration> QSemaphore::try_acquire_until(std::chrono::time_point<Clock, Duration> timeout)
+ \since 6.3
+
+ This function is provided for \c{std::counting_semaphore} compatibility.
+
+ It is equivalent to calling \c{tryAcquire(1, timeout - Clock::now())},
+ which means that adjustments to \c{Clock} are ignored while waiting.
+
+ \sa tryAcquire(), try_acquire(), try_acquire_for()
+*/
+
+/*!
\class QSemaphoreReleaser
\brief The QSemaphoreReleaser class provides exception-safe deferral of a QSemaphore::release() call.
\since 5.10