thread/Mutex: add method ScopeLock::Unlock()
This commit is contained in:
parent
cc9345e703
commit
eca6b9f0af
@ -45,17 +45,25 @@ class Mutex : public PosixMutex {};
|
|||||||
class ScopeLock {
|
class ScopeLock {
|
||||||
Mutex &mutex;
|
Mutex &mutex;
|
||||||
|
|
||||||
|
bool active = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScopeLock(Mutex &_mutex):mutex(_mutex) {
|
ScopeLock(Mutex &_mutex):mutex(_mutex) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
};
|
};
|
||||||
|
|
||||||
~ScopeLock() {
|
~ScopeLock() {
|
||||||
mutex.unlock();
|
if (active)
|
||||||
|
mutex.unlock();
|
||||||
};
|
};
|
||||||
|
|
||||||
ScopeLock(const ScopeLock &other) = delete;
|
ScopeLock(const ScopeLock &other) = delete;
|
||||||
ScopeLock &operator=(const ScopeLock &other) = delete;
|
ScopeLock &operator=(const ScopeLock &other) = delete;
|
||||||
|
|
||||||
|
void Unlock() {
|
||||||
|
mutex.unlock();
|
||||||
|
active = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user