/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
};
using FooSingletonTL = SingletonThreadLocal<Foo>;
FooSingletonTL theFooSingleton;
-}
+} // namespace
TEST(SingletonThreadLocalTest, OneSingletonPerThread) {
- const std::size_t targetThreadCount{64};
+ static constexpr std::size_t targetThreadCount{64};
std::atomic<std::size_t> completedThreadCount{0};
Synchronized<std::unordered_set<Foo*>> fooAddresses{};
std::vector<std::thread> threads{};
- auto threadFunction =
- [&fooAddresses, targetThreadCount, &completedThreadCount] {
- fooAddresses.wlock()->emplace(&FooSingletonTL::get());
- ++completedThreadCount;
- while (completedThreadCount < targetThreadCount) {
- std::this_thread::yield();
- }
- };
+ auto threadFunction = [&fooAddresses, &completedThreadCount] {
+ fooAddresses.wlock()->emplace(&FooSingletonTL::get());
+ ++completedThreadCount;
+ while (completedThreadCount < targetThreadCount) {
+ std::this_thread::yield();
+ }
+ };
{
for (std::size_t threadCount{0}; threadCount < targetThreadCount;
++threadCount) {