Commit ac1eaff6 authored by Max Kellermann's avatar Max Kellermann

thread/Mutex: add class ScopeUnlock()

parent 45f6129a
......@@ -58,4 +58,24 @@ public:
ScopeLock &operator=(const ScopeLock &other) = delete;
};
/**
* Within the scope of an instance, this class will keep a #Mutex
* unlocked.
*/
class ScopeUnlock {
Mutex &mutex;
public:
explicit ScopeUnlock(Mutex &_mutex):mutex(_mutex) {
mutex.unlock();
};
~ScopeUnlock() {
mutex.lock();
}
ScopeUnlock(const ScopeUnlock &other) = delete;
ScopeUnlock &operator=(const ScopeUnlock &other) = delete;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment