Skip to content

Commit

Permalink
Switch to HeapTimekeeper as default Timekeeper
Browse files Browse the repository at this point in the history
Summary:
See D49060468 for the analysis.

The old timekeeper is kept behind a kill-switch just in case.

Reviewed By: dmm-fb

Differential Revision: D49061304

fbshipit-source-id: b7dc4c41d42f3dd03e5505aaa69ab08b0c6890e5
  • Loading branch information
ot authored and facebook-github-bot committed Sep 10, 2023
1 parent cc12ac2 commit 75652db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
18 changes: 15 additions & 3 deletions folly/futures/Future.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@

#include <folly/Likely.h>
#include <folly/Singleton.h>
#include <folly/futures/HeapTimekeeper.h>
#include <folly/futures/ThreadWheelTimekeeper.h>
#include <folly/portability/GFlags.h>

FOLLY_GFLAGS_DEFINE_bool(
folly_futures_use_thread_wheel_timekeeper,
false,
"Use ThreadWheelTimekeeper for the default Future timekeeper singleton");

namespace folly {
namespace futures {
Expand Down Expand Up @@ -81,9 +88,14 @@ SemiFuture<Unit> wait(std::shared_ptr<fibers::Baton> baton) {
namespace detail {

namespace {
Singleton<Timekeeper, TimekeeperSingletonTag> gTimekeeperSingleton([] {
return new ThreadWheelTimekeeper;
});
Singleton<Timekeeper, TimekeeperSingletonTag> gTimekeeperSingleton(
[]() -> Timekeeper* {
if (FLAGS_folly_futures_use_thread_wheel_timekeeper) {
return new ThreadWheelTimekeeper;
} else {
return new HeapTimekeeper;
}
});
} // namespace

std::shared_ptr<Timekeeper> getTimekeeperSingleton() {
Expand Down
9 changes: 9 additions & 0 deletions folly/futures/test/HeapTimekeeperTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<HeapTimekeeper*>(detail::getTimekeeperSingleton().get()) !=
nullptr);
}

} // namespace folly
9 changes: 0 additions & 9 deletions folly/futures/test/ThreadWheelTimekeeperTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadWheelTimekeeper*>(
detail::getTimekeeperSingleton().get()) != nullptr);
}

} // namespace folly

0 comments on commit 75652db

Please sign in to comment.