2017-01-25 18:40:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-07-28 17:34:02 +00:00
|
|
|
#include <shared_mutex>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/ProfileEvents.h>
|
|
|
|
#include <Common/Stopwatch.h>
|
2017-01-25 18:40:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
class ProfilingScopedWriteRWLock
|
|
|
|
{
|
|
|
|
public:
|
2017-07-28 17:34:02 +00:00
|
|
|
ProfilingScopedWriteRWLock(std::shared_mutex & rwl, ProfileEvents::Event event) :
|
2017-04-01 07:20:54 +00:00
|
|
|
watch(),
|
|
|
|
scoped_write_lock(rwl)
|
|
|
|
{
|
|
|
|
ProfileEvents::increment(event, watch.elapsed());
|
|
|
|
}
|
2017-01-25 18:40:44 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Stopwatch watch;
|
2017-07-28 17:34:02 +00:00
|
|
|
std::unique_lock<std::shared_mutex> scoped_write_lock;
|
2017-01-25 18:40:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ProfilingScopedReadRWLock
|
|
|
|
{
|
|
|
|
public:
|
2017-07-28 17:34:02 +00:00
|
|
|
ProfilingScopedReadRWLock(std::shared_mutex & rwl, ProfileEvents::Event event) :
|
2017-04-01 07:20:54 +00:00
|
|
|
watch(),
|
|
|
|
scoped_read_lock(rwl)
|
|
|
|
{
|
|
|
|
ProfileEvents::increment(event, watch.elapsed());
|
|
|
|
}
|
2017-01-25 18:40:44 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Stopwatch watch;
|
2017-07-28 17:34:02 +00:00
|
|
|
std::shared_lock<std::shared_mutex> scoped_read_lock;
|
2017-01-25 18:40:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|