mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 21:24:28 +00:00
41 lines
799 B
C++
41 lines
799 B
C++
#pragma once
|
|
|
|
#include <shared_mutex>
|
|
#include <Common/ProfileEvents.h>
|
|
#include <Common/Stopwatch.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
class ProfilingScopedWriteRWLock
|
|
{
|
|
public:
|
|
ProfilingScopedWriteRWLock(std::shared_mutex & rwl, ProfileEvents::Event event) :
|
|
watch(),
|
|
scoped_write_lock(rwl)
|
|
{
|
|
ProfileEvents::increment(event, watch.elapsed());
|
|
}
|
|
|
|
private:
|
|
Stopwatch watch;
|
|
std::unique_lock<std::shared_mutex> scoped_write_lock;
|
|
};
|
|
|
|
class ProfilingScopedReadRWLock
|
|
{
|
|
public:
|
|
ProfilingScopedReadRWLock(std::shared_mutex & rwl, ProfileEvents::Event event) :
|
|
watch(),
|
|
scoped_read_lock(rwl)
|
|
{
|
|
ProfileEvents::increment(event, watch.elapsed());
|
|
}
|
|
|
|
private:
|
|
Stopwatch watch;
|
|
std::shared_lock<std::shared_mutex> scoped_read_lock;
|
|
};
|
|
|
|
}
|