From 2e1318f691547e159b28fb738858738e621464e4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 1 May 2023 16:05:21 -0700 Subject: [PATCH] QSemaphore: add a note to update to noexcept in Qt 7 The QSemaphore acquire & release functions, plus the constructor and destructor, can be made noexcept on platforms that use futexes (currently, Linux and Windows; likely macOS by the time we make 7.0). I didn't make the change right now because the acquire and release functions have narrow contracts on the int n values. I didn't make that change now because it make a mess of the code, for little gain as this class isn't used that often. Plus, we may want to investigate whether we want to keep the multi-token semaphore functionality around (something neither POSIX sem_t nor std::counting_semaphore have), or split that off into a separate class like QBasicMutex / QMutex / QRecursiveMutex was done. Change-Id: Ieab617d69f3b4b54ab30fffd175b27813728f2ce Reviewed-by: Thiago Macieira Reviewed-by: Ahmad Samir --- src/corelib/thread/qsemaphore.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp index af34a7bb39..a7b423e4e7 100644 --- a/src/corelib/thread/qsemaphore.cpp +++ b/src/corelib/thread/qsemaphore.cpp @@ -300,7 +300,12 @@ QSemaphore::~QSemaphore() */ void QSemaphore::acquire(int n) { +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) +# warning "Move the Q_ASSERT to inline code, make QSemaphore have wide contract, " \ + "and mark noexcept where futexes are in use." +#else Q_ASSERT_X(n >= 0, "QSemaphore::acquire", "parameter 'n' must be non-negative"); +#endif if (futexAvailable()) { futexSemaphoreTryAcquire(u, n, QDeadlineTimer::Forever);