Timed wait operations for spin-only Baton
[folly.git] / folly / synchronization / test / BatonTestHelpers.h
index a0bba6e051166e7a7ab07e64b2c0ada8c193c4d4..0884927a79b2ab7113cc2b2f53be19d4df55f0d0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2016-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.
@@ -25,16 +25,16 @@ namespace test {
 
 typedef DeterministicSchedule DSched;
 
-template <template <typename> class Atom, bool Blocking>
+template <bool MayBlock, template <typename> class Atom>
 void run_basic_test() {
-  Baton<Atom, Blocking> b;
+  Baton<MayBlock, Atom> b;
   b.post();
   b.wait();
 }
 
-template <template <typename> class Atom, bool Blocking>
+template <bool MayBlock, template <typename> class Atom>
 void run_pingpong_test(int numRounds) {
-  using B = Baton<Atom, Blocking>;
+  using B = Baton<MayBlock, Atom>;
   B batons[17];
   B& a = batons[0];
   B& b = batons[16]; // to get it on a different cache line
@@ -53,17 +53,17 @@ void run_pingpong_test(int numRounds) {
   DSched::join(thr);
 }
 
-template <template <typename> class Atom, typename Clock>
+template <bool MayBlock, template <typename> class Atom, typename Clock>
 void run_basic_timed_wait_tests() {
-  Baton<Atom> b;
+  Baton<MayBlock, Atom> b;
   b.post();
   // tests if early delivery works fine
   EXPECT_TRUE(b.try_wait_until(Clock::now()));
 }
 
-template <template <typename> class Atom, typename Clock>
+template <bool MayBlock, template <typename> class Atom, typename Clock>
 void run_timed_wait_tmo_tests() {
-  Baton<Atom> b;
+  Baton<MayBlock, Atom> b;
 
   auto thr = DSched::thread([&] {
     bool rv = b.try_wait_until(Clock::now() + std::chrono::milliseconds(1));
@@ -73,9 +73,9 @@ void run_timed_wait_tmo_tests() {
   DSched::join(thr);
 }
 
-template <template <typename> class Atom, typename Clock>
+template <bool MayBlock, template <typename> class Atom, typename Clock>
 void run_timed_wait_regular_test() {
-  Baton<Atom> b;
+  Baton<MayBlock, Atom> b;
 
   auto thr = DSched::thread([&] {
     // To wait forever we'd like to use time_point<Clock>::max, but
@@ -104,9 +104,9 @@ void run_timed_wait_regular_test() {
   DSched::join(thr);
 }
 
-template <template <typename> class Atom, bool Blocking>
+template <bool MayBlock, template <typename> class Atom>
 void run_try_wait_tests() {
-  Baton<Atom, Blocking> b;
+  Baton<MayBlock, Atom> b;
   EXPECT_FALSE(b.ready());
   EXPECT_FALSE(b.try_wait());
   b.post();