From 7dd3b72a8ca193ac82a602a17e161bc573e5f44c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 15 Dec 2015 23:33:07 +0100 Subject: [PATCH] db/DatabaseLock: add ScopeDatabaseLock::unlock() --- src/db/DatabaseLock.hxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/db/DatabaseLock.hxx b/src/db/DatabaseLock.hxx index 786c97899..253eb73fb 100644 --- a/src/db/DatabaseLock.hxx +++ b/src/db/DatabaseLock.hxx @@ -84,13 +84,26 @@ db_unlock(void) } class ScopeDatabaseLock { + bool locked = true; + public: ScopeDatabaseLock() { db_lock(); } ~ScopeDatabaseLock() { + if (locked) + db_unlock(); + } + + /** + * Unlock the mutex now, making the destructor a no-op. + */ + void unlock() { + assert(locked); + db_unlock(); + locked = false; } };