From 91c938f57c450a5a8fe388668cb31a40c6f985c2 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Sat, 3 May 2014 08:33:22 -0700 Subject: [PATCH] common/RWLock: add explicit unlock() to *Lockers Signed-off-by: Yehuda Sadeh --- src/common/RWLock.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/common/RWLock.h b/src/common/RWLock.h index eb2faaaf7c0bd..6f3ffe315b6d6 100644 --- a/src/common/RWLock.h +++ b/src/common/RWLock.h @@ -114,24 +114,46 @@ public: class RLocker { const RWLock &m_lock; + bool locked; + public: RLocker(const RWLock& lock) : m_lock(lock) { m_lock.get_read(); + locked = true; + } + void unlock() { + assert(locked); + m_lock.unlock(); + locked = false; } ~RLocker() { - m_lock.put_read(); + if (locked) { + m_lock.unlock(); + } } }; class WLocker { RWLock &m_lock; + bool locked; + public: WLocker(RWLock& lock) : m_lock(lock) { m_lock.get_write(); + locked = true; + } + void unlock() { + assert(locked); + m_lock.unlock(); + locked = false; } ~WLocker() { - m_lock.put_write(); + if (locked) { + m_lock.unlock(); + } + } + }; } }; }; -- 2.39.5