QSemaphoreReleaser Class
The QSemaphoreReleaser class provides exception-safe deferral of a QSemaphore::release() call. More…
| Header | #include <QSemaphoreReleaser> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QSemaphoreReleaser() | |
| QSemaphoreReleaser(QSemaphore &s, int n = 1) | |
| QSemaphoreReleaser(QSemaphore *s, int n = 1) | |
| QSemaphoreReleaser(QSemaphoreReleaser &&other) | |
| QSemaphoreReleaser & | operator=(QSemaphoreReleaser &&other) |
| ~QSemaphoreReleaser() | |
| void | swap(QSemaphoreReleaser &other) |
| QSemaphore * | semaphore() const |
| QSemaphore * | cancel() |
Detailed Description
A QSemaphoreReleaser releases a number of resources on a QSemaphore when it is destroyed, unless cancel() was called first.
QSemaphore sem;
void work()
{
QSemaphoreReleaser releaser(sem);
// the semaphore is released when this function returns
}
See also QSemaphore.
Differences from Qt
None.
Member Function Documentation
QSemaphoreReleaser::QSemaphoreReleaser()
Constructs a releaser that does nothing.
QSemaphoreReleaser::QSemaphoreReleaser(QSemaphore &s, int n = 1)
Constructs a releaser that releases n resources on s when it is destroyed.
QSemaphoreReleaser::QSemaphoreReleaser(QSemaphore *s, int n = 1)
This is an overloaded function.
Constructs a releaser that releases n resources on s when it is destroyed. If s is nullptr, the releaser does nothing.
QSemaphoreReleaser::QSemaphoreReleaser(QSemaphoreReleaser &&other)
Move-constructs a releaser from other, which no longer releases anything afterwards.
QSemaphoreReleaser::~QSemaphoreReleaser()
Destroys the releaser and releases the resources on the semaphore, unless it was cancelled.
QSemaphore * QSemaphoreReleaser::cancel()
Cancels the pending release and returns the semaphore the releaser was operating on, or nullptr if there was none. The destructor then does nothing.
QSemaphoreReleaser & QSemaphoreReleaser::operator=(QSemaphoreReleaser &&other)
Move-assigns other to this releaser and returns a reference to it. A release pending on this releaser happens first.
QSemaphore * QSemaphoreReleaser::semaphore() const
Returns the semaphore the releaser operates on, or nullptr if there is none or the release was cancelled.
See also cancel().
void QSemaphoreReleaser::swap(QSemaphoreReleaser &other)
Swaps the semaphore and count of this releaser with those of other.