diff --git a/folly/concurrency/test/BUCK b/folly/concurrency/test/BUCK index 7c78dab2f58..ddc7469c5cb 100644 --- a/folly/concurrency/test/BUCK +++ b/folly/concurrency/test/BUCK @@ -97,6 +97,7 @@ cpp_unittest( "//folly/hash:hash", "//folly/portability:gflags", "//folly/portability:gtest", + "//folly/synchronization:latch", "//folly/test:deterministic_schedule", ], ) diff --git a/folly/concurrency/test/ConcurrentHashMapTest.cpp b/folly/concurrency/test/ConcurrentHashMapTest.cpp index dea314f4825..3232812389d 100644 --- a/folly/concurrency/test/ConcurrentHashMapTest.cpp +++ b/folly/concurrency/test/ConcurrentHashMapTest.cpp @@ -22,19 +22,14 @@ #include #include -#include #include #include #include #include #include +#include #include -#if FOLLY_CPLUSPLUS >= 202002L -// std::latch becomes visible in C++20 mode -#include -#endif - using namespace folly::test; using namespace folly; using namespace std; @@ -1140,8 +1135,6 @@ TYPED_TEST_P(ConcurrentHashMapTest, ConcurrentInsertClear) { } TYPED_TEST_P(ConcurrentHashMapTest, StressTestReclamation) { -// This needs C++20 for std::latch. -#if FOLLY_CPLUSPLUS >= 202002L // Create a map where we keep reclaiming a lot of objects that are linked to // one node. @@ -1167,7 +1160,7 @@ TYPED_TEST_P(ConcurrentHashMapTest, StressTestReclamation) { // It should be uncommon to have more than 2^32 concurrent accesses. static constexpr uint64_t num_threads = std::numeric_limits::max(); static constexpr uint64_t iters = 100; - std::latch start{num_threads}; + folly::Latch start(num_threads); for (uint64_t t = 0; t < num_threads; t++) { threads.push_back(lib::thread([t, &map, &start]() { start.arrive_and_wait(); @@ -1187,7 +1180,6 @@ TYPED_TEST_P(ConcurrentHashMapTest, StressTestReclamation) { for (auto& t : threads) { join; } -#endif } REGISTER_TYPED_TEST_SUITE_P( diff --git a/folly/test/BUCK b/folly/test/BUCK index b8e0f635051..581e4c0fad7 100644 --- a/folly/test/BUCK +++ b/folly/test/BUCK @@ -1490,6 +1490,7 @@ cpp_unittest( "//folly/experimental/io:fs_util", "//folly/lang:keep", "//folly/portability:gtest", + "//folly/synchronization:latch", "//folly/testing:test_util", ], external_deps = [ @@ -1722,6 +1723,7 @@ cpp_binary( "//folly:thread_local", "//folly/lang:keep", "//folly/portability:gflags", + "//folly/synchronization:latch", ], external_deps = [ "glog", diff --git a/folly/test/SingletonThreadLocalTest.cpp b/folly/test/SingletonThreadLocalTest.cpp index cb59b2796e6..2d5163b4d04 100644 --- a/folly/test/SingletonThreadLocalTest.cpp +++ b/folly/test/SingletonThreadLocalTest.cpp @@ -18,7 +18,6 @@ #include #endif -#include #include #include #include @@ -31,6 +30,7 @@ #include #include #include +#include #include using namespace folly; @@ -60,7 +60,7 @@ TEST(SingletonThreadLocalTest, TryGet) { TEST(SingletonThreadLocalTest, OneSingletonPerThread) { static constexpr std::size_t targetThreadCount{64}; - std::latch allSingletonsCreated(targetThreadCount); + folly::Latch allSingletonsCreated(targetThreadCount); Synchronized> fooAddresses{}; std::vector threads{}; auto threadFunction = [&fooAddresses, &allSingletonsCreated] { diff --git a/folly/test/ThreadLocalBenchmark.cpp b/folly/test/ThreadLocalBenchmark.cpp index 8dfafab8356..ad99f46ddb5 100644 --- a/folly/test/ThreadLocalBenchmark.cpp +++ b/folly/test/ThreadLocalBenchmark.cpp @@ -18,7 +18,6 @@ #include -#include #include #include @@ -28,6 +27,7 @@ #include #include #include +#include using namespace folly; @@ -137,9 +137,9 @@ BENCHMARK(BM_tlp_access_all_threads_iterate, iters) { folly::ThreadLocalPtr var; folly::BenchmarkSuspender braces; std::vector threads{folly::to_unsigned(FLAGS_num_threads)}; - std::latch prep{FLAGS_num_threads}; - std::latch work{FLAGS_num_threads + 1}; - std::latch done{1}; + folly::Latch prep(FLAGS_num_threads); + folly::Latch work(FLAGS_num_threads + 1); + folly::Latch done(1); for (auto& th : threads) { th = std::jthread([&] { var.reset(new int(3));