/Users/deen/code/yugabyte-db/src/yb/util/shared_lock.h
Line | Count | Source |
1 | | // |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
5 | | // in compliance with the License. You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
10 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
11 | | // or implied. See the License for the specific language governing permissions and limitations |
12 | | // under the License. |
13 | | |
14 | | #ifndef YB_UTIL_SHARED_LOCK_H |
15 | | #define YB_UTIL_SHARED_LOCK_H |
16 | | |
17 | | #include <shared_mutex> |
18 | | |
19 | | #include "yb/gutil/thread_annotations.h" |
20 | | |
21 | | namespace yb { |
22 | | |
23 | | // A wrapper around Boost shared lock that supports thread annotations. |
24 | | template<typename Mutex> |
25 | | class SCOPED_CAPABILITY SharedLock { |
26 | | public: |
27 | 914M | explicit SharedLock(Mutex &mutex) ACQUIRE_SHARED(mutex) : m_lock(mutex) {} yb::SharedLock<yb::rw_semaphore>::SharedLock(yb::rw_semaphore&) Line | Count | Source | 27 | 342k | explicit SharedLock(Mutex &mutex) ACQUIRE_SHARED(mutex) : m_lock(mutex) {} |
yb::SharedLock<yb::rw_spinlock>::SharedLock(yb::rw_spinlock&) Line | Count | Source | 27 | 836M | explicit SharedLock(Mutex &mutex) ACQUIRE_SHARED(mutex) : m_lock(mutex) {} |
yb::SharedLock<yb::RWMutex>::SharedLock(yb::RWMutex&) Line | Count | Source | 27 | 51.1M | explicit SharedLock(Mutex &mutex) ACQUIRE_SHARED(mutex) : m_lock(mutex) {} |
yb::SharedLock<std::__1::shared_timed_mutex>::SharedLock(std::__1::shared_timed_mutex&) Line | Count | Source | 27 | 26.2M | explicit SharedLock(Mutex &mutex) ACQUIRE_SHARED(mutex) : m_lock(mutex) {} |
|
28 | 914M | ~SharedLock() RELEASE() = default; yb::SharedLock<yb::rw_semaphore>::~SharedLock() Line | Count | Source | 28 | 342k | ~SharedLock() RELEASE() = default; |
yb::SharedLock<yb::rw_spinlock>::~SharedLock() Line | Count | Source | 28 | 836M | ~SharedLock() RELEASE() = default; |
yb::SharedLock<yb::RWMutex>::~SharedLock() Line | Count | Source | 28 | 51.1M | ~SharedLock() RELEASE() = default; |
yb::SharedLock<std::__1::shared_timed_mutex>::~SharedLock() Line | Count | Source | 28 | 26.2M | ~SharedLock() RELEASE() = default; |
|
29 | | |
30 | | private: |
31 | | std::shared_lock<Mutex> m_lock; |
32 | | }; |
33 | | |
34 | | } // namespace yb |
35 | | |
36 | | #endif // YB_UTIL_SHARED_LOCK_H |