QSemaphoreReleaser: plaster with [[nodiscard]]

It's a RAII class, and RAII classes should be marked [[nodiscard]] at
the class as well as the ctor level.

Task-number: QTBUG-104164
Change-Id: Ie877e261cfe602410d9d9bb3acc658d0bb7c4e72
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 6fc908c001a274360d3ff431ba16a1df9d8af089)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-06-13 09:33:08 +02:00 committed by Qt Cherry-pick Bot
parent 7c6883d5db
commit df759d34eb

View File

@ -61,14 +61,18 @@ bool QSemaphore::tryAcquire(int n, int timeout)
}
#endif
class QSemaphoreReleaser
class [[nodiscard]] QSemaphoreReleaser
{
public:
Q_NODISCARD_CTOR
QSemaphoreReleaser() = default;
Q_NODISCARD_CTOR
explicit QSemaphoreReleaser(QSemaphore &sem, int n = 1) noexcept
: m_sem(&sem), m_n(n) {}
Q_NODISCARD_CTOR
explicit QSemaphoreReleaser(QSemaphore *sem, int n = 1) noexcept
: m_sem(sem), m_n(n) {}
Q_NODISCARD_CTOR
QSemaphoreReleaser(QSemaphoreReleaser &&other) noexcept
: m_sem(other.cancel()), m_n(other.m_n) {}
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSemaphoreReleaser)