Skip to content

Commit

Permalink
migrate fields of type folly::SharedMutex to be marked as mutable in …
Browse files Browse the repository at this point in the history
…fbcode (assorted)

Summary:
The nested-name lock-holder `folly::SharedMutex::ReadHolder` accepts `folly::SharedMutex const&`, i.e., as ref-to-const, and it internally does a `const_cast` to remove the `const`. This internal `const_cast` is necessary because members `folly::SharedMutex::lock_shared` and related member functions are not `const`-qualified.

This lock-holder interface is a convenience since a shared-lock on a shared-mutex instance are commonly acquired in `const`-qualified class member functions, where the shared-mutex instance is a class data member and access to it from a `const`-qualified member function implicitly has only `const`-access to the shared-mutex instance.

But `std::shared_lock` does not have this convenience. It is the canonical lock-holder for shared locks and we wish to migrate all uses of `folly::SharedMutex::ReadHolder` to `std::shared_lock`. So we must mark relevant shared-mutex instances with `mutable`.

As a small shortcut, we search for and mark all class data members of type `folly::SharedMutex` as `mutable`.

Reviewed By: luciang

Differential Revision: D52921022

fbshipit-source-id: bca727c89d153cee583b2862fdf70fdd4e22ff05
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Jan 23, 2024
1 parent cf3c2fc commit 561bfa4
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mcrouter/AsyncWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AsyncWriter {
size_t maxQueueSize_;
std::atomic<size_t> queueSize_{0};
std::atomic<bool> stopped_{false};
folly::SharedMutex runLock_;
mutable folly::SharedMutex runLock_;

folly::fibers::FiberManager fiberManager_;
folly::EventBase eventBase_;
Expand Down
2 changes: 1 addition & 1 deletion mcrouter/CallbackPool-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct CallbackPool<Args...>::CallbackHandleImpl {
template <typename... Args>
struct CallbackPool<Args...>::Data {
std::set<CallbackHandleImpl*> callbacks;
folly::SharedMutex callbackLock;
mutable folly::SharedMutex callbackLock;
};

/* CallbackPool */
Expand Down
2 changes: 1 addition & 1 deletion mcrouter/Observable.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Observable {
CallbackPool<const Data&, const Data&> pool_;
Data data_;

folly::SharedMutex dataLock_;
mutable folly::SharedMutex dataLock_;
};
} // namespace mcrouter
} // namespace memcache
Expand Down
2 changes: 1 addition & 1 deletion mcrouter/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Proxy : public ProxyBase {
bool beingDestroyed_{false};

/** Read/write lock for config pointer */
folly::SharedMutex configLock_;
mutable folly::SharedMutex configLock_;
std::shared_ptr<ProxyConfig<RouterInfo>> config_;

typename RouterInfo::RouterStats requestStats_;
Expand Down

0 comments on commit 561bfa4

Please sign in to comment.