From 34703d412d97158e34f163da73ffad158a919b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 12 Dec 2020 10:11:17 +0100 Subject: [PATCH] Make ScopedMutexLock nothrow. Wrong order of lock/unlock calls are programming errors and should be treated as such. --- source/vibe/core/sync.d | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/vibe/core/sync.d b/source/vibe/core/sync.d index f85d436..9f29d4b 100644 --- a/source/vibe/core/sync.d +++ b/source/vibe/core/sync.d @@ -132,21 +132,22 @@ struct ScopedMutexLock(M) @property bool locked() const { return m_locked; } void unlock() - { + in (this.locked) + do { enforce(m_locked); m_mutex.unlock(); m_locked = false; } bool tryLock() - { - enforce(!m_locked); + in (!this.locked) + do { return m_locked = m_mutex.tryLock(); } void lock() - { - enforce(!m_locked); + in (!this.locked) + do { m_locked = true; m_mutex.lock(); }