Commit d3a08687 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by facebook-github-bot-4

Avoid deprecated Singleton<T>::get() in folly/futures

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
parent 19fb62bd
...@@ -33,7 +33,7 @@ namespace folly { ...@@ -33,7 +33,7 @@ namespace folly {
class Timekeeper; class Timekeeper;
namespace detail { namespace detail {
Timekeeper* getTimekeeperSingleton(); std::shared_ptr<Timekeeper> getTimekeeperSingleton();
} }
template <class T> template <class T>
...@@ -889,8 +889,10 @@ Future<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) { ...@@ -889,8 +889,10 @@ Future<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) {
std::atomic<bool> token {false}; std::atomic<bool> token {false};
}; };
std::shared_ptr<Timekeeper> tks;
if (!tk) { if (!tk) {
tk = folly::detail::getTimekeeperSingleton(); tks = folly::detail::getTimekeeperSingleton();
tk = DCHECK_NOTNULL(tks.get());
} }
auto ctx = std::make_shared<Context>(std::move(e)); auto ctx = std::make_shared<Context>(std::move(e));
......
...@@ -32,8 +32,10 @@ template class Future<double>; ...@@ -32,8 +32,10 @@ template class Future<double>;
namespace folly { namespace futures { namespace folly { namespace futures {
Future<Unit> sleep(Duration dur, Timekeeper* tk) { Future<Unit> sleep(Duration dur, Timekeeper* tk) {
std::shared_ptr<Timekeeper> tks;
if (LIKELY(!tk)) { if (LIKELY(!tk)) {
tk = folly::detail::getTimekeeperSingleton(); tks = folly::detail::getTimekeeperSingleton();
tk = DCHECK_NOTNULL(tks.get());
} }
return tk->after(dur); return tk->after(dur);
} }
......
...@@ -138,8 +138,8 @@ Future<Unit> ThreadWheelTimekeeper::after(Duration dur) { ...@@ -138,8 +138,8 @@ Future<Unit> ThreadWheelTimekeeper::after(Duration dur) {
namespace detail { namespace detail {
Timekeeper* getTimekeeperSingleton() { std::shared_ptr<Timekeeper> getTimekeeperSingleton() {
return timekeeperSingleton_.get(); return timekeeperSingleton_.try_get();
} }
} // detail } // detail
......
...@@ -37,7 +37,7 @@ struct TimekeeperFixture : public testing::Test { ...@@ -37,7 +37,7 @@ struct TimekeeperFixture : public testing::Test {
timeLord_(folly::detail::getTimekeeperSingleton()) timeLord_(folly::detail::getTimekeeperSingleton())
{} {}
Timekeeper* timeLord_; std::shared_ptr<Timekeeper> timeLord_;
}; };
TEST_F(TimekeeperFixture, after) { TEST_F(TimekeeperFixture, after) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment