/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2011-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 <atomic>
#include <condition_variable>
+#include <memory>
#include <thread>
#include <glog/logging.h>
-#include <gtest/gtest.h>
#include <folly/Benchmark.h>
-#include <folly/Hash.h>
+#include <folly/hash/Hash.h>
#include <folly/portability/GFlags.h>
+#include <folly/portability/GTest.h>
+#include <folly/system/ThreadId.h>
using namespace folly;
}
}
}
-}
+} // namespace
// Slow test with fewer threads where there are more busy waits and
// many calls to readFull(). This attempts to test as many of the
// iteration, threads[1] performs 2 iterations, threads[2] performs
// 3 iterations, and so on.
for (uint32_t i = 0; i < kNumThreads; ++i) {
- threads[i].reset(new std::thread(Runner, &g_counter_for_mt_slow, i + 1));
+ threads[i] =
+ std::make_unique<std::thread>(Runner, &g_counter_for_mt_slow, i + 1);
}
// Variable to grab current counter value.
int32_t counter_value;
// iteration, threads[1] performs 2 iterations, threads[2] performs
// 3 iterations, and so on.
for (uint32_t i = 0; i < kNumThreads; ++i) {
- threads[i].reset(new std::thread(Runner, &g_counter_for_mt_fast, i + 1));
+ threads[i] =
+ std::make_unique<std::thread>(Runner, &g_counter_for_mt_fast, i + 1);
}
// Let the threads run to completion.
{
std::vector<std::thread> threads; \
for (int i = 0; i < FLAGS_numThreads; ++i) { \
threads.push_back(std::thread([&]() { \
- for (int i = 0; i < iterPerThread; ++i) { \
+ for (int j = 0; j < iterPerThread; ++j) { \
inc_stmt; \
} \
})); \
std::atomic<int64_t> ints_[kBuckets_];
inline void inc(int64_t val = 1) {
- int bucket = hash::twang_mix64(
- uint64_t(pthread_self())) & (kBuckets_ - 1);
- std::atomic_fetch_add(&ints_[bucket], val);
+ int buck = hash::twang_mix64(folly::getCurrentThreadID()) & (kBuckets_ - 1);
+ std::atomic_fetch_add(&ints_[buck], val);
}
// read the first few and extrapolate