Skip to content

Commit

Permalink
migrate from nested-name WriteHolder in mcrouter/
Browse files Browse the repository at this point in the history
Summary: Migrate from nested-name `{mutex}::WriteHolder` to `std::unique_lock`.

Reviewed By: dmm-fb

Differential Revision: D52231368

fbshipit-source-id: 019da7f1d5ea17a74c663c0dff03ee602b8b38c3
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Dec 19, 2023
1 parent 665e318 commit 31d546b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions mcrouter/AsyncWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ AsyncWriter::~AsyncWriter() {

void AsyncWriter::stop() noexcept {
{
folly::SharedMutex::WriteHolder lock(runLock_);
std::unique_lock lock(runLock_);
if (stopped_) {
return;
}
Expand All @@ -53,7 +53,7 @@ void AsyncWriter::stop() noexcept {
}

bool AsyncWriter::start(folly::StringPiece threadName) {
folly::SharedMutex::WriteHolder lock(runLock_);
std::unique_lock lock(runLock_);
if (thread_.joinable() || stopped_) {
return false;
}
Expand Down Expand Up @@ -110,15 +110,15 @@ bool AsyncWriter::run(std::function<void()> f) {
}

void AsyncWriter::increaseMaxQueueSize(size_t add) {
folly::SharedMutex::WriteHolder lock(runLock_);
std::unique_lock lock(runLock_);
// Don't touch maxQueueSize_ if it's already unlimited (zero).
if (maxQueueSize_ != 0) {
maxQueueSize_ += add;
}
}

void AsyncWriter::makeQueueSizeUnlimited() {
folly::SharedMutex::WriteHolder lock(runLock_);
std::unique_lock lock(runLock_);
maxQueueSize_ = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions mcrouter/CallbackPool-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct CallbackPool<Args...>::CallbackHandleImpl {
CallbackHandleImpl(const CallbackHandleImpl&) = delete;
CallbackHandleImpl& operator=(const CallbackHandleImpl&) = delete;
~CallbackHandleImpl() {
folly::SharedMutex::WriteHolder lck(data_->callbackLock);
std::unique_lock lck(data_->callbackLock);
data_->callbacks.erase(this);
}

Expand All @@ -33,7 +33,7 @@ struct CallbackPool<Args...>::CallbackHandleImpl {

CallbackHandleImpl(std::shared_ptr<Data> data, OnUpdateFunc func)
: data_(std::move(data)), func_(std::move(func)) {
folly::SharedMutex::WriteHolder lck(data_->callbackLock);
std::unique_lock lck(data_->callbackLock);
data_->callbacks.insert(this);
}
};
Expand Down
2 changes: 1 addition & 1 deletion mcrouter/Observable-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Data Observable<Data>::get() {

template <class Data>
void Observable<Data>::set(Data data) {
folly::SharedMutex::WriteHolder lck(dataLock_);
std::unique_lock lck(dataLock_);
auto old = std::move(data_);
data_ = std::move(data);
// no copy here, because old and data are passed by const reference
Expand Down
2 changes: 1 addition & 1 deletion mcrouter/Proxy-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Proxy<RouterInfo>::getConfigLocked() const {
template <class RouterInfo>
std::shared_ptr<ProxyConfig<RouterInfo>> Proxy<RouterInfo>::swapConfig(
std::shared_ptr<ProxyConfig<RouterInfo>> newConfig) {
folly::SharedMutex::WriteHolder lg(configLock_);
std::unique_lock lg(configLock_);
auto old = std::move(config_);
config_ = std::move(newConfig);
return old;
Expand Down
2 changes: 1 addition & 1 deletion mcrouter/lib/network/AsyncMcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ void AsyncMcServer::join() {
}

void AsyncMcServer::setTicketKeySeeds(wangle::TLSTicketKeySeeds seeds) {
folly::SharedMutex::WriteHolder writeGuard(tlsTicketKeySeedsLock_);
std::unique_lock writeGuard(tlsTicketKeySeedsLock_);
tlsTicketKeySeeds_ = std::move(seeds);
}

Expand Down
8 changes: 4 additions & 4 deletions mcrouter/lib/network/McSSLUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,24 @@ bool McSSLUtil::verifySSLWithDefaultBehavior(
void McSSLUtil::setApplicationKtlsFunctions(
SSLToKtlsFunction func,
KtlsStatsFunction statsFunc) {
folly::SharedMutex::WriteHolder wh(getMutex());
std::unique_lock wh(getMutex());
getKtlsFuncRef() = std::move(func);
getKtlsStatsFuncRef() = std::move(statsFunc);
}

void McSSLUtil::setApplicationSSLVerifier(SSLVerifyFunction func) {
folly::SharedMutex::WriteHolder wh(getMutex());
std::unique_lock wh(getMutex());
getAppFuncRef() = std::move(func);
}

void McSSLUtil::setClientIdentityHook(apache::thrift::ClientIdentityHook func) {
folly::SharedMutex::WriteHolder wh(getMutex());
std::unique_lock wh(getMutex());
getClientIdentityHookFuncRef() = std::move(func);
}

void McSSLUtil::setDropCertificateX509PayloadFunction(
DropCertificateX509PayloadFunction func) {
folly::SharedMutex::WriteHolder wh(getMutex());
std::unique_lock wh(getMutex());
getDropCertificateX509PayloadFuncRef() = std::move(func);
}

Expand Down

0 comments on commit 31d546b

Please sign in to comment.