Skip to content

Commit

Permalink
cut lock-holder deducer functions
Browse files Browse the repository at this point in the history
Summary: With C++17 and constructor template-argument deduction, we no longer need these deducer functions.

Reviewed By: ilvokhin

Differential Revision: D59974386

fbshipit-source-id: 979dc51da07812db6e8c5e1e53d8a5da7852f38c
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Jul 22, 2024
1 parent b153eb1 commit 404b94b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 111 deletions.
8 changes: 4 additions & 4 deletions folly/observer/detail/ObserverManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,23 @@ class ObserverManager {
}

static void waitForAllUpdates() {
tryWaitForAllUpdatesImpl([=](auto& m) { return make_unique_lock(m); });
tryWaitForAllUpdatesImpl([=](auto& m) { return std::unique_lock(m); });
}
static bool tryWaitForAllUpdates() {
return tryWaitForAllUpdatesImpl(
[=](auto& m) { return make_unique_lock(m, std::try_to_lock); });
[=](auto& m) { return std::unique_lock(m, std::try_to_lock); });
}
template <typename Rep, typename Period>
static bool tryWaitForAllUpdatesFor(
std::chrono::duration<Rep, Period> timeout) {
return tryWaitForAllUpdatesImpl(
[=](auto& m) { return make_unique_lock(m, timeout); });
[=](auto& m) { return std::unique_lock(m, timeout); });
}
template <typename Clock, typename Duration>
static bool tryWaitForAllUpdatesUntil(
std::chrono::time_point<Clock, Duration> deadline) {
return tryWaitForAllUpdatesImpl(
[=](auto& m) { return make_unique_lock(m, deadline); });
[=](auto& m) { return std::unique_lock(m, deadline); });
}

class DependencyRecorder {
Expand Down
1 change: 0 additions & 1 deletion folly/stats/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ cpp_library(
"//folly:spin_lock",
"//folly/concurrency:cache_locality",
"//folly/lang:bits",
"//folly/synchronization:lock",
],
)

Expand Down
7 changes: 3 additions & 4 deletions folly/stats/DigestBuilder-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <folly/concurrency/CacheLocality.h>
#include <folly/lang/Bits.h>
#include <folly/synchronization/Lock.h>

namespace folly {

Expand Down Expand Up @@ -48,7 +47,7 @@ DigestT DigestBuilder<DigestT>::build() {
std::vector<double> newBuffer;
std::unique_ptr<DigestT> newDigest;

auto g = make_unique_lock(cpuLocalBuffer.mutex);
auto g = std::unique_lock(cpuLocalBuffer.mutex);
bool hasDigest =
cpuLocalBuffer.digest != nullptr && !cpuLocalBuffer.digest->empty();
// If at least one merge happened, bufferSize_ was reached.
Expand Down Expand Up @@ -97,7 +96,7 @@ void DigestBuilder<DigestT>::append(double value) {
const auto numBuffers = cpuLocalBuffers_.size();
auto cpuLocalBuf =
&cpuLocalBuffers_[AccessSpreader<>::cachedCurrent(numBuffers)];
auto g = make_unique_lock(cpuLocalBuf->mutex, std::try_to_lock);
auto g = std::unique_lock(cpuLocalBuf->mutex, std::try_to_lock);
if (FOLLY_UNLIKELY(!g.owns_lock())) {
// If the mutex is already held by another thread, either build() is
// running, or this or that thread have a stale stripe (possibly because the
Expand All @@ -106,7 +105,7 @@ void DigestBuilder<DigestT>::append(double value) {
AccessSpreader<>::invalidateCachedCurrent();
cpuLocalBuf =
&cpuLocalBuffers_[AccessSpreader<>::cachedCurrent(numBuffers)];
g = make_unique_lock(cpuLocalBuf->mutex);
g = std::unique_lock(cpuLocalBuf->mutex);
}

cpuLocalBuf->buffer.push_back(value);
Expand Down
48 changes: 0 additions & 48 deletions folly/synchronization/Lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,54 +524,6 @@ class hybrid_lock_guard
template <typename Mutex, typename... A>
explicit hybrid_lock_guard(Mutex&, A const&...) -> hybrid_lock_guard<Mutex>;

// make_unique_lock
//
// Returns a unique_lock constructed with the given arguments. Deduces the
// mutex type.
struct make_unique_lock_fn {
template <typename Mutex, typename... A>
FOLLY_NODISCARD unique_lock<Mutex> operator()(Mutex& mutex, A&&... a) const {
return unique_lock<Mutex>{mutex, static_cast<A&&>(a)...};
}
};
inline constexpr make_unique_lock_fn make_unique_lock{};

// make_shared_lock
//
// Returns a shared_lock constructed with the given arguments. Deduces the
// mutex type.
struct make_shared_lock_fn {
template <typename Mutex, typename... A>
FOLLY_NODISCARD shared_lock<Mutex> operator()(Mutex& mutex, A&&... a) const {
return shared_lock<Mutex>{mutex, static_cast<A&&>(a)...};
}
};
inline constexpr make_shared_lock_fn make_shared_lock{};

// make_upgrade_lock
//
// Returns an upgrade_lock constructed with the given arguments. Deduces the
// mutex type.
struct make_upgrade_lock_fn {
template <typename Mutex, typename... A>
FOLLY_NODISCARD upgrade_lock<Mutex> operator()(Mutex& mutex, A&&... a) const {
return upgrade_lock<Mutex>{mutex, static_cast<A&&>(a)...};
}
};
inline constexpr make_upgrade_lock_fn make_upgrade_lock{};

// make_hybrid_lock
//
// Returns a hybrid_lock constructed with the given arguments. Deduces the
// mutex type.
struct make_hybrid_lock_fn {
template <typename Mutex, typename... A>
FOLLY_NODISCARD hybrid_lock<Mutex> operator()(Mutex& mutex, A&&... a) const {
return hybrid_lock<Mutex>{mutex, static_cast<A&&>(a)...};
}
};
inline constexpr make_hybrid_lock_fn make_hybrid_lock{};

} // namespace folly

FOLLY_NAMESPACE_STD_BEGIN
Expand Down
49 changes: 0 additions & 49 deletions folly/synchronization/Utility.h

This file was deleted.

10 changes: 5 additions & 5 deletions folly/synchronization/test/RWSpinLockTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ template <typename RWSpinLockType>
static void run(RWSpinLockType& lock) {
while (!stopThread.load(std::memory_order_acquire)) {
if (rand() % 10 == 0) { // write
auto guard = make_unique_lock(lock);
auto guard = std::unique_lock(lock);
} else { // read
auto guard = make_shared_lock(lock);
auto guard = std::shared_lock(lock);
}
}
}
Expand Down Expand Up @@ -196,20 +196,20 @@ TEST(RWSpinLock, concurrentHolderTest) {
while (!stop.load(std::memory_order_acquire)) {
auto r = (uint32_t)(rand()) % 10;
if (r < 3) { // starts from write lock
auto wg = make_unique_lock(lock);
auto wg = std::unique_lock(lock);
auto ug = folly::transition_lock<folly::upgrade_lock>(wg);
auto rg = folly::transition_lock<std::shared_lock>(ug);
writes.fetch_add(1, std::memory_order_acq_rel);
} else if (r < 6) { // starts from upgrade lock
auto ug = make_upgrade_lock(lock);
auto ug = folly::upgrade_lock(lock);
if (r < 4) {
auto wg = folly::transition_lock<std::unique_lock>(ug);
} else {
auto rg = folly::transition_lock<std::shared_lock>(ug);
}
upgrades.fetch_add(1, std::memory_order_acq_rel);
} else {
auto rg = make_shared_lock(lock);
auto rg = std::shared_lock(lock);
reads.fetch_add(1, std::memory_order_acq_rel);
}
}
Expand Down

0 comments on commit 404b94b

Please sign in to comment.