/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2015-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <thread>
-#include <folly/Baton.h>
#include <folly/experimental/RCURefCount.h>
#include <folly/experimental/TLRefCount.h>
-
-#include <gtest/gtest.h>
+#include <folly/portability/GTest.h>
+#include <folly/synchronization/Baton.h>
namespace folly {
std::vector<std::thread> ts;
folly::Baton<> threadBatons[numThreads];
for (size_t t = 0; t < numThreads; ++t) {
- ts.emplace_back([&count, &b, &got0, numIters, t, &threadBatons]() {
- for (size_t i = 0; i < numIters; ++i) {
- auto ret = ++count;
-
- EXPECT_TRUE(ret > 1);
- if (i == 0) {
- threadBatons[t].post();
- }
- }
+ ts.emplace_back([&count, &b, &got0, t, &threadBatons] {
+ for (size_t i = 0; i < numIters; ++i) {
+ auto ret = ++count;
- if (t == 0) {
- b.post();
+ EXPECT_TRUE(ret > 1);
+ if (i == 0) {
+ threadBatons[t].post();
}
+ }
+
+ if (t == 0) {
+ b.post();
+ }
- for (size_t i = 0; i < numIters; ++i) {
- auto ret = --count;
+ for (size_t i = 0; i < numIters; ++i) {
+ auto ret = --count;
- if (ret == 0) {
- ++got0;
- EXPECT_EQ(numIters - 1, i);
- }
+ if (ret == 0) {
+ ++got0;
+ EXPECT_EQ(numIters - 1, i);
}
- });
+ }
+ });
}
for (size_t t = 0; t < numThreads; ++t) {
}
template <typename RefCount>
-void stressTest() {
- constexpr size_t kItersCount = 10000;
-
- for (size_t i = 0; i < kItersCount; ++i) {
+void stressTest(size_t itersCount) {
+ for (size_t i = 0; i < itersCount; ++i) {
RefCount count;
std::mutex mutex;
int a{1};
}
TEST(RCURefCount, Stress) {
- stressTest<TLRefCount>();
+ stressTest<RCURefCount>(100000);
}
TEST(TLRefCount, Stress) {
- stressTest<TLRefCount>();
-}
+ // This is absurdly slow, so we can't
+ // do it that many times.
+ stressTest<TLRefCount>(500);
}
+} // namespace folly