Use std::this_thread::yield rather than sched_yield
[folly.git] / folly / test / CacheLocalityBenchmark.cpp
index 4815cc24cac3be7e9affb0cca99a1284db1ef115..dbb2d6ac676b71983a9ec848f2dfc798ac0bc179 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 <folly/detail/CacheLocality.h>
 
-#include <sched.h>
 #include <memory>
 #include <thread>
-#include <type_traits>
 #include <unordered_map>
+
 #include <glog/logging.h>
+
 #include <folly/Benchmark.h>
 
 using namespace folly::detail;
@@ -31,7 +31,6 @@ using namespace folly::detail;
   template <typename dummy>                            \
   struct tag {};                                       \
   }                                                    \
-  DECLARE_ACCESS_SPREADER_TYPE(tag)                    \
   namespace folly {                                    \
   namespace detail {                                   \
   template <>                                          \
@@ -161,7 +160,7 @@ static void contentionAtWidth(size_t iters, size_t stripes, size_t work) {
   std::vector<std::thread> threads;
   while (threads.size() < numThreads) {
     threads.push_back(std::thread([&, iters, stripes, work]() {
-      std::atomic<size_t>* counters[stripes];
+      auto counters = std::vector<std::atomic<size_t>*>(stripes);
       for (size_t i = 0; i < stripes; ++i) {
         counters[i] =
             new (raw.data() + counterAlignment * i) std::atomic<size_t>();
@@ -169,7 +168,7 @@ static void contentionAtWidth(size_t iters, size_t stripes, size_t work) {
 
       ready++;
       while (!go.load()) {
-        sched_yield();
+        std::this_thread::yield();
       }
       std::atomic<int> localWork(0);
       for (size_t i = iters; i > 0; --i) {
@@ -189,7 +188,7 @@ static void contentionAtWidth(size_t iters, size_t stripes, size_t work) {
   }
 
   while (ready < numThreads) {
-    sched_yield();
+    std::this_thread::yield();
   }
   braces.dismiss();
   go = true;
@@ -210,7 +209,7 @@ static void atomicIncrBaseline(size_t iters,
   while (threads.size() < numThreads) {
     threads.push_back(std::thread([&]() {
       while (!go.load()) {
-        sched_yield();
+        std::this_thread::yield();
       }
       std::atomic<size_t> localCounter(0);
       std::atomic<int> localWork(0);