fix build when sanitizers are enabled and jemalloc is disabled
[folly.git] / folly / test / ThreadCachedIntTest.cpp
index 97ce60c207587e53a4412f80c8b55f208696d898..8709abf60321c7efcf4b297af7c76656979e0e16 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 <atomic>
 #include <condition_variable>
+#include <memory>
 #include <thread>
 
 #include <glog/logging.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;
 
@@ -69,7 +71,7 @@ void Runner(Counter* counter, uint32_t iterations) {
     }
   }
 }
-}
+} // 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
@@ -85,7 +87,8 @@ TEST_F(ThreadCachedIntTest, MultithreadedSlow) {
   // 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;
@@ -140,7 +143,8 @@ TEST_F(ThreadCachedIntTest, MultithreadedFast) {
   // 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.
   {
@@ -274,7 +278,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 +302,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