Skip to content

Commit

Permalink
Use BRAVO rwlock for ReplaceablePtr (#11786)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaori335 authored Oct 1, 2024
1 parent 4be7bcc commit c58b0db
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/iocore/cache/P_CacheHosting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,8 +150,8 @@ template <typename T> class ReplaceablePtr
class ScopedReader
{
public:
ScopedReader(ReplaceablePtr<T> *ptr) : ptr(ptr) { ptr->m.lock_shared(); }
~ScopedReader() { ptr->m.unlock_shared(); }
ScopedReader(ReplaceablePtr<T> *ptr) : ptr(ptr) { ptr->m.lock_shared(_token); }
~ScopedReader() { ptr->m.unlock_shared(_token); }

const T *
operator->()
Expand All @@ -168,6 +170,7 @@ template <typename T> class ReplaceablePtr
ScopedReader &operator=(const ScopedReader &) = delete;

ReplaceablePtr<T> *ptr;
ts::bravo::Token _token = 0;
};

// ScopedWriter constructs an object which is allowed to read and modify the
Expand Down Expand Up @@ -206,8 +209,8 @@ template <typename T> class ReplaceablePtr
ReplaceablePtr(const ReplaceablePtr &) = delete;
ReplaceablePtr &operator=(const ReplaceablePtr &) = delete;

std::unique_ptr<T> h = nullptr;
std::shared_mutex m;
std::unique_ptr<T> h = nullptr;
ts::bravo::shared_mutex m;

friend class ReplaceablePtr::ScopedReader;
};
Expand Down

0 comments on commit c58b0db

Please sign in to comment.