summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-09-04 19:46:59 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-09-05 15:57:42 +0200
commit2c0ad8dd3ae8e8a01e6128267d57cde20bcebddb (patch)
tree8803801247d270e9ac1c5402c521ddf9aef1b156 /src/corelib/thread
parent72106832e4dfd9a773541e4490d5e594caf1cf50 (diff)
QSemaphoreReleaser: two minor code improvements
- use qExchange() in cancel() - use cancel() instead of manual pointer manipulations in the move ctor Change-Id: Ica3a3a1e339500c5e5a0c0646e7a95c7c5d435db Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qsemaphore.h7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/corelib/thread/qsemaphore.h b/src/corelib/thread/qsemaphore.h
index 58c12997ad..b3b9b52052 100644
--- a/src/corelib/thread/qsemaphore.h
+++ b/src/corelib/thread/qsemaphore.h
@@ -80,8 +80,7 @@ public:
explicit QSemaphoreReleaser(QSemaphore *sem, int n = 1) noexcept
: m_sem(sem), m_n(n) {}
QSemaphoreReleaser(QSemaphoreReleaser &&other) noexcept
- : m_sem(other.m_sem), m_n(other.m_n)
- { other.m_sem = nullptr; }
+ : m_sem(other.cancel()), m_n(other.m_n) {}
QSemaphoreReleaser &operator=(QSemaphoreReleaser &&other) noexcept
{ QSemaphoreReleaser moved(std::move(other)); swap(moved); return *this; }
@@ -102,9 +101,7 @@ public:
QSemaphore *cancel() noexcept
{
- QSemaphore *old = m_sem;
- m_sem = nullptr;
- return old;
+ return qExchange(m_sem, nullptr);
}
private: