Summary: [Folly] Avoid deprecated `Singleton<T>::get()` in `folly/futures`.
Changes `getTimekeeperSingleton()` to return a `shared_ptr<Timekeeper>`, and patches its call-sites.
Additionally, have the call-sites keep the singleton instance alive for the duration that it is being directly used.
Reviewed By: ddrcoder
Differential Revision:
D2702361
fb-gh-sync-id:
82b72ee514dc4f2a7f7522af8b2e92b34df063d6
class Timekeeper;
namespace detail {
- Timekeeper* getTimekeeperSingleton();
+ std::shared_ptr<Timekeeper> getTimekeeperSingleton();
}
template <class T>
std::atomic<bool> token {false};
};
+ std::shared_ptr<Timekeeper> tks;
if (!tk) {
- tk = folly::detail::getTimekeeperSingleton();
+ tks = folly::detail::getTimekeeperSingleton();
+ tk = DCHECK_NOTNULL(tks.get());
}
auto ctx = std::make_shared<Context>(std::move(e));
namespace folly { namespace futures {
Future<Unit> sleep(Duration dur, Timekeeper* tk) {
+ std::shared_ptr<Timekeeper> tks;
if (LIKELY(!tk)) {
- tk = folly::detail::getTimekeeperSingleton();
+ tks = folly::detail::getTimekeeperSingleton();
+ tk = DCHECK_NOTNULL(tks.get());
}
return tk->after(dur);
}
namespace detail {
-Timekeeper* getTimekeeperSingleton() {
- return timekeeperSingleton_.get();
+std::shared_ptr<Timekeeper> getTimekeeperSingleton() {
+ return timekeeperSingleton_.try_get();
}
} // detail
timeLord_(folly::detail::getTimekeeperSingleton())
{}
- Timekeeper* timeLord_;
+ std::shared_ptr<Timekeeper> timeLord_;
};
TEST_F(TimekeeperFixture, after) {