ClickHouse/base/ext/unlock_guard.h

28 lines
360 B
C++
Raw Normal View History

2015-10-05 00:33:43 +00:00
#pragma once
namespace ext
{
template <typename T>
class unlock_guard
{
public:
unlock_guard(T & mutex_) : mutex(mutex_)
{
mutex.unlock();
}
2015-10-05 00:33:43 +00:00
~unlock_guard()
{
mutex.lock();
}
2015-10-05 00:33:43 +00:00
unlock_guard(const unlock_guard &) = delete;
unlock_guard & operator=(const unlock_guard &) = delete;
2015-10-05 00:33:43 +00:00
private:
T & mutex;
2015-10-05 00:33:43 +00:00
};
}