1
1
#pragma once
2
2
3
- #include < tbb/reader_writer_lock.h >
3
+ #include < shared_mutex >
4
4
5
5
#include " common/macros.h"
6
6
7
7
namespace noisepage ::common {
8
8
9
9
/* *
10
- * A cheap and easy shared (reader-writer) latch, currently wraps tbb::reader_writer_lock. From Intel's docs:
11
- *
12
- * A reader_writer_lock is scalable and nonrecursive. The implementation handles lock requests on a first-come
13
- * first-serve basis except that writers have preference over readers. Waiting threads busy wait, which can degrade
14
- * system performance if the wait is long. However, if the wait is typically short, a reader_writer_lock can provide
15
- * performance competitive with other mutexes.
10
+ * A cheap(?) and easy shared (reader-writer) latch, currently wraps std::shared_mutex.
16
11
*/
17
12
class SharedLatch {
18
13
public:
@@ -24,7 +19,7 @@ class SharedLatch {
24
19
/* *
25
20
* Acquire shared lock on mutex.
26
21
*/
27
- void LockShared () { latch_.lock_read (); }
22
+ void LockShared () { latch_.lock_shared (); }
28
23
29
24
/* *
30
25
* Try to acquire exclusive lock on mutex.
@@ -36,12 +31,17 @@ class SharedLatch {
36
31
* Try to acquire shared lock on mutex.
37
32
* @return true if lock acquired, false otherwise.
38
33
*/
39
- bool TryLockShared () { return latch_.try_lock_read (); }
34
+ bool TryLockShared () { return latch_.try_lock_shared (); }
40
35
41
36
/* *
42
- * Release lock.
37
+ * Release exclusive ownership of lock.
43
38
*/
44
- void Unlock () { latch_.unlock (); }
39
+ void UnlockExclusive () { latch_.unlock (); }
40
+
41
+ /* *
42
+ * Release shared ownership of lock.
43
+ */
44
+ void UnlockShared () { latch_.unlock_shared (); }
45
45
46
46
/* *
47
47
* Scoped read latch that guarantees releasing the latch when destructed.
@@ -56,7 +56,7 @@ class SharedLatch {
56
56
/* *
57
57
* Release write lock (if acquired).
58
58
*/
59
- ~ScopedSharedLatch () { rw_latch_->Unlock (); }
59
+ ~ScopedSharedLatch () { rw_latch_->UnlockShared (); }
60
60
DISALLOW_COPY_AND_MOVE (ScopedSharedLatch)
61
61
62
62
private:
@@ -76,14 +76,14 @@ class SharedLatch {
76
76
/* *
77
77
* Release read lock (if acquired).
78
78
*/
79
- ~ScopedExclusiveLatch () { rw_latch_->Unlock (); }
79
+ ~ScopedExclusiveLatch () { rw_latch_->UnlockExclusive (); }
80
80
DISALLOW_COPY_AND_MOVE (ScopedExclusiveLatch)
81
81
private:
82
82
SharedLatch *const rw_latch_;
83
83
};
84
84
85
85
private:
86
- tbb::reader_writer_lock latch_;
86
+ std::shared_mutex latch_;
87
87
};
88
88
89
89
} // namespace noisepage::common
0 commit comments