diff --git a/folly/futures/Future.cpp b/folly/futures/Future.cpp index e0bbe3cb39b..d1f3e0024b7 100644 --- a/folly/futures/Future.cpp +++ b/folly/futures/Future.cpp @@ -18,7 +18,14 @@ #include #include +#include #include +#include + +FOLLY_GFLAGS_DEFINE_bool( + folly_futures_use_thread_wheel_timekeeper, + false, + "Use ThreadWheelTimekeeper for the default Future timekeeper singleton"); namespace folly { namespace futures { @@ -81,9 +88,14 @@ SemiFuture wait(std::shared_ptr baton) { namespace detail { namespace { -Singleton gTimekeeperSingleton([] { - return new ThreadWheelTimekeeper; -}); +Singleton gTimekeeperSingleton( + []() -> Timekeeper* { + if (FLAGS_folly_futures_use_thread_wheel_timekeeper) { + return new ThreadWheelTimekeeper; + } else { + return new HeapTimekeeper; + } + }); } // namespace std::shared_ptr getTimekeeperSingleton() { diff --git a/folly/futures/test/HeapTimekeeperTest.cpp b/folly/futures/test/HeapTimekeeperTest.cpp index 4e549b6ce26..5b87c017c31 100644 --- a/folly/futures/test/HeapTimekeeperTest.cpp +++ b/folly/futures/test/HeapTimekeeperTest.cpp @@ -22,4 +22,13 @@ namespace folly { INSTANTIATE_TYPED_TEST_SUITE_P( HeapTimekeeperTest, TimekeeperTest, HeapTimekeeper); +TEST(TimekeeperSingletonTest, ExpectedType) { + // This is just to check that the un-mocked default timekeeper singleton + // Implementation is covered by some instantiation of the test suite. If the + // default implementation is changed this test should be moved accordingly. + ASSERT_TRUE( + dynamic_cast(detail::getTimekeeperSingleton().get()) != + nullptr); +} + } // namespace folly diff --git a/folly/futures/test/ThreadWheelTimekeeperTest.cpp b/folly/futures/test/ThreadWheelTimekeeperTest.cpp index b8760d4f4dc..32861362ef2 100644 --- a/folly/futures/test/ThreadWheelTimekeeperTest.cpp +++ b/folly/futures/test/ThreadWheelTimekeeperTest.cpp @@ -22,13 +22,4 @@ namespace folly { INSTANTIATE_TYPED_TEST_SUITE_P( ThreadWheelTimekeeperTest, TimekeeperTest, ThreadWheelTimekeeper); -TEST(TimekeeperSingletonTest, ExpectedType) { - // This is just to check that the un-mocked default timekeeper singleton - // implementation is covered by some instantiation of the test suite. If the - // default implementation is changed this test should be moved accordingly. - ASSERT_TRUE( - dynamic_cast( - detail::getTimekeeperSingleton().get()) != nullptr); -} - } // namespace folly