1#pragma once
2
3#include <shared_mutex>
4#include <Common/ProfileEvents.h>
5#include <Common/Stopwatch.h>
6
7
8namespace DB
9{
10class ProfilingScopedWriteRWLock
11{
12public:
13 ProfilingScopedWriteRWLock(std::shared_mutex & rwl, ProfileEvents::Event event) :
14 watch(),
15 scoped_write_lock(rwl)
16 {
17 ProfileEvents::increment(event, watch.elapsed());
18 }
19
20private:
21 Stopwatch watch;
22 std::unique_lock<std::shared_mutex> scoped_write_lock;
23};
24
25class ProfilingScopedReadRWLock
26{
27public:
28 ProfilingScopedReadRWLock(std::shared_mutex & rwl, ProfileEvents::Event event) :
29 watch(),
30 scoped_read_lock(rwl)
31 {
32 ProfileEvents::increment(event, watch.elapsed());
33 }
34
35private:
36 Stopwatch watch;
37 std::shared_lock<std::shared_mutex> scoped_read_lock;
38};
39
40}
41