mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-14 03:25:15 +00:00
46 lines
806 B
C++
46 lines
806 B
C++
#pragma once
|
|
|
|
#include <Poco/RWLock.h>
|
|
#include <DB/Common/ProfileEvents.h>
|
|
#include <DB/Common/Stopwatch.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;
|
|
};
|
|
|
|
}
|