Make it easier to swap in a scalable reader-writer mutex.
Change-Id: I04837646dfb41c2b545af54312dac63f47473dd6
Reviewed-on: https://code-review.googlesource.com/c/re2/+/58430
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/re2/dfa.cc b/re2/dfa.cc
index 3f6571d..f292ff1 100644
--- a/re2/dfa.cc
+++ b/re2/dfa.cc
@@ -167,6 +167,9 @@
typedef std::unordered_set<State*, StateHash, StateEqual> StateSet;
private:
+ // Make it easier to swap in a scalable reader-writer mutex.
+ using CacheMutex = Mutex;
+
enum {
// Indices into start_ for unanchored searches.
// Add kStartAnchored for anchored searches.
@@ -331,7 +334,7 @@
// while holding cache_mutex_ for writing, to avoid interrupting other
// readers. Any State* pointers are only valid while cache_mutex_
// is held.
- Mutex cache_mutex_;
+ CacheMutex cache_mutex_;
int64_t mem_budget_; // Total memory budget for all States.
int64_t state_budget_; // Amount of memory remaining for new States.
StateSet state_cache_; // All States computed so far.
@@ -1106,7 +1109,7 @@
class DFA::RWLocker {
public:
- explicit RWLocker(Mutex* mu);
+ explicit RWLocker(CacheMutex* mu);
~RWLocker();
// If the lock is only held for reading right now,
@@ -1116,14 +1119,14 @@
void LockForWriting();
private:
- Mutex* mu_;
+ CacheMutex* mu_;
bool writing_;
RWLocker(const RWLocker&) = delete;
RWLocker& operator=(const RWLocker&) = delete;
};
-DFA::RWLocker::RWLocker(Mutex* mu) : mu_(mu), writing_(false) {
+DFA::RWLocker::RWLocker(CacheMutex* mu) : mu_(mu), writing_(false) {
mu_->ReaderLock();
}