move ApplyTuple to functional/
[folly.git] / folly / test / ThreadCachedIntTest.cpp
index a17c4cb6b5c3b006a74a745789b2b5de344be1a2..e09c780fd4b2d6cad11ebb9e3e66990975daad55 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
 #include <thread>
 
 #include <glog/logging.h>
-#include <gtest/gtest.h>
 
 #include <folly/Benchmark.h>
 #include <folly/Hash.h>
+#include <folly/ThreadId.h>
 #include <folly/portability/GFlags.h>
+#include <folly/portability/GTest.h>
 
 using namespace folly;
 
@@ -274,7 +275,7 @@ MAKE_MT_CACHE_SIZE_BM(32);
     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;                                         \
             }                                                   \
           }));                                                  \
@@ -298,9 +299,8 @@ struct ShardedAtomicInt {
   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