18 #include <unordered_set> 25 using namespace folly;
28 static std::atomic<std::size_t> fooCreatedCount{0};
29 static std::atomic<std::size_t> fooDeletedCount{0};
41 TEST(SingletonThreadLocalTest, OneSingletonPerThread) {
42 static constexpr std::size_t targetThreadCount{64};
43 std::atomic<std::size_t> completedThreadCount{0};
45 std::vector<std::thread>
threads{};
46 auto threadFunction = [&fooAddresses, &completedThreadCount] {
48 ++completedThreadCount;
49 while (completedThreadCount < targetThreadCount) {
54 for (std::size_t threadCount{0}; threadCount < targetThreadCount;
56 threads.emplace_back(threadFunction);
62 EXPECT_EQ(threads.size(), fooAddresses.rlock()->size());
63 EXPECT_EQ(threads.size(), fooCreatedCount);
64 EXPECT_EQ(threads.size(), fooDeletedCount);
67 TEST(SingletonThreadLocalTest, MoveConstructibleMake) {
70 Foo(
int a_,
int b_) :
a(a_),
b(b_) {}
72 Foo& operator=(Foo&&) =
default;
76 Foo operator()()
const {
84 TEST(SingletonThreadLocalTest, NotMoveConstructibleMake) {
87 Foo(
int a_,
int b_) :
a(a_),
b(b_) {}
89 Foo& operator=(Foo&&) =
delete;
93 Foo* operator()(
unsigned char (&buf)[
sizeof(Foo)])
const {
94 return new (buf) Foo(3, 4);
101 TEST(SingletonThreadLocalTest, AccessAfterFastPathDestruction) {
102 static std::atomic<int>
counter{};
111 auto th = std::thread([] {
129 data.reset(
new int(0));
136 data.reset(
new int(0));
143 TEST(SingletonThreadLocalTest, Reused) {
144 for (
auto i = 0u;
i < 2u; ++
i) {
#define EXPECT_EQ(val1, val2)
#define FOLLY_DECLARE_REUSED(name,...)
—— Concurrent Priority Queue Implementation ——
std::vector< std::thread::id > threads
constexpr auto data(C &c) -> decltype(c.data())
FOLLY_EXPORT static FOLLY_ALWAYS_INLINE T & get()
std::atomic< int > counter
void join(const Delim &delimiter, Iterator begin, Iterator end, String &output)
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
TEST(SequencedExecutor, CPUThreadPoolExecutor)