db/DatabaseLock: add ScopeDatabaseLock::unlock()
This commit is contained in:
parent
aeccccb33d
commit
7dd3b72a8c
@ -84,13 +84,26 @@ db_unlock(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ScopeDatabaseLock {
|
class ScopeDatabaseLock {
|
||||||
|
bool locked = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScopeDatabaseLock() {
|
ScopeDatabaseLock() {
|
||||||
db_lock();
|
db_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
~ScopeDatabaseLock() {
|
~ScopeDatabaseLock() {
|
||||||
|
if (locked)
|
||||||
|
db_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlock the mutex now, making the destructor a no-op.
|
||||||
|
*/
|
||||||
|
void unlock() {
|
||||||
|
assert(locked);
|
||||||
|
|
||||||
db_unlock();
|
db_unlock();
|
||||||
|
locked = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user