1 | #pragma once |
---|---|
2 | |
3 | #include <shared_mutex> |
4 | #include <Common/ProfileEvents.h> |
5 | #include <Common/Stopwatch.h> |
6 | |
7 | |
8 | namespace DB |
9 | { |
10 | class ProfilingScopedWriteRWLock |
11 | { |
12 | public: |
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 | |
20 | private: |
21 | Stopwatch watch; |
22 | std::unique_lock<std::shared_mutex> scoped_write_lock; |
23 | }; |
24 | |
25 | class ProfilingScopedReadRWLock |
26 | { |
27 | public: |
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 | |
35 | private: |
36 | Stopwatch watch; |
37 | std::shared_lock<std::shared_mutex> scoped_read_lock; |
38 | }; |
39 | |
40 | } |
41 |