From eca6b9f0af9e1a194ded436df2b9540fefefbee4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 2 May 2016 23:32:44 +0200 Subject: [PATCH] thread/Mutex: add method ScopeLock::Unlock() --- src/thread/Mutex.hxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/thread/Mutex.hxx b/src/thread/Mutex.hxx index 1756bddf3..7e4e0fd2e 100644 --- a/src/thread/Mutex.hxx +++ b/src/thread/Mutex.hxx @@ -45,17 +45,25 @@ class Mutex : public PosixMutex {}; class ScopeLock { Mutex &mutex; + bool active = true; + public: ScopeLock(Mutex &_mutex):mutex(_mutex) { mutex.lock(); }; ~ScopeLock() { - mutex.unlock(); + if (active) + mutex.unlock(); }; ScopeLock(const ScopeLock &other) = delete; ScopeLock &operator=(const ScopeLock &other) = delete; + + void Unlock() { + mutex.unlock(); + active = false; + } }; /**