db/DatabaseLock: add ScopeDatabaseLock::unlock()

This commit is contained in:
Max Kellermann 2015-12-15 23:33:07 +01:00
parent aeccccb33d
commit 7dd3b72a8c

View File

@ -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;
}
};