From c58b0db41d61f372fb975e06d1c76550a7eaba92 Mon Sep 17 00:00:00 2001 From: Masaori Koshiba Date: Wed, 2 Oct 2024 08:00:10 +0900 Subject: [PATCH] Use BRAVO rwlock for ReplaceablePtr (#11786) --- src/iocore/cache/P_CacheHosting.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/iocore/cache/P_CacheHosting.h b/src/iocore/cache/P_CacheHosting.h index 1802ba76650..9e83e09db44 100644 --- a/src/iocore/cache/P_CacheHosting.h +++ b/src/iocore/cache/P_CacheHosting.h @@ -28,6 +28,8 @@ #include "tscore/MatcherUtils.h" #include "tscore/HostLookup.h" +#include "tsutil/Bravo.h" + #define CACHE_MEM_FREE_TIMEOUT HRTIME_SECONDS(1) class StripeSM; @@ -148,8 +150,8 @@ template class ReplaceablePtr class ScopedReader { public: - ScopedReader(ReplaceablePtr *ptr) : ptr(ptr) { ptr->m.lock_shared(); } - ~ScopedReader() { ptr->m.unlock_shared(); } + ScopedReader(ReplaceablePtr *ptr) : ptr(ptr) { ptr->m.lock_shared(_token); } + ~ScopedReader() { ptr->m.unlock_shared(_token); } const T * operator->() @@ -168,6 +170,7 @@ template class ReplaceablePtr ScopedReader &operator=(const ScopedReader &) = delete; ReplaceablePtr *ptr; + ts::bravo::Token _token = 0; }; // ScopedWriter constructs an object which is allowed to read and modify the @@ -206,8 +209,8 @@ template class ReplaceablePtr ReplaceablePtr(const ReplaceablePtr &) = delete; ReplaceablePtr &operator=(const ReplaceablePtr &) = delete; - std::unique_ptr h = nullptr; - std::shared_mutex m; + std::unique_ptr h = nullptr; + ts::bravo::shared_mutex m; friend class ReplaceablePtr::ScopedReader; };