ClickHouse/dbms/include/DB/Common/ProfilingScopedRWLock.h
proller f04dffc05c External dictionary profiling [#CLICKHOUSE-2197] (#381)
* Profiling external cached dictonaries [#CLICKHOUSE-2197]

* style
2017-01-25 22:40:44 +04:00

46 lines
774 B
C++

#pragma once
#include <Poco/RWLock.h>
#include <DB/Common/ProfileEvents.h>
/*
TODO: replace locks with std::shared_mutex - std::unique_lock - std::shared_lock when c++17
*/
namespace DB
{
class ProfilingScopedWriteRWLock
{
public:
ProfilingScopedWriteRWLock(Poco::RWLock & rwl, ProfileEvents::Event event) :
watch(),
scoped_write_lock(rwl)
{
ProfileEvents::increment(event, watch.elapsed());
}
private:
Stopwatch watch;
Poco::ScopedWriteRWLock scoped_write_lock;
};
class ProfilingScopedReadRWLock
{
public:
ProfilingScopedReadRWLock(Poco::RWLock & rwl, ProfileEvents::Event event) :
watch(),
scoped_read_lock(rwl)
{
ProfileEvents::increment(event, watch.elapsed());
}
private:
Stopwatch watch;
Poco::ScopedReadRWLock scoped_read_lock;
};
}