2017-01-25 18:40:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Poco/RWLock.h>
|
|
|
|
#include <DB/Common/ProfileEvents.h>
|
2017-02-02 22:08:19 +00:00
|
|
|
#include <DB/Common/Stopwatch.h>
|
2017-01-25 18:40:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|