From f54fbf88038aacc4bcc0f3bf98995375fddcde78 Mon Sep 17 00:00:00 2001 From: Steve O'Brien Date: Wed, 7 Oct 2015 13:11:06 -0700 Subject: [PATCH] Singleton: remove dependency on Future Summary: Singletons requires Futures, and Futures indirectly (via HHWheelTimeKeeper) require Singletons. This breaks the dependency. It removes a Future-using API which will be replaced with a better alternative. Reviewed By: @luciang Differential Revision: D2517807 fb-gh-sync-id: 93df371a74d0f80dc8c55fb0eadd0b688b27b525 --- folly/Singleton.cpp | 9 +++------ folly/Singleton.h | 5 +---- folly/test/SingletonTest.cpp | 5 ++--- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/folly/Singleton.cpp b/folly/Singleton.cpp index 5e4e88be..52f3957f 100644 --- a/folly/Singleton.cpp +++ b/folly/Singleton.cpp @@ -128,7 +128,7 @@ void SingletonVault::doEagerInit() { } } -Future SingletonVault::doEagerInitVia(Executor* exe) { +void SingletonVault::doEagerInitVia(Executor* exe) { std::unordered_set singletonSet; { RWSpinLock::ReadHolder rh(&stateMutex_); @@ -139,16 +139,13 @@ Future SingletonVault::doEagerInitVia(Executor* exe) { singletonSet = eagerInitSingletons_; // copy set of pointers } - std::vector> resultFutures; for (auto* single : singletonSet) { - resultFutures.emplace_back(via(exe).then([single] { + exe->add([single] { if (!single->creationStarted()) { single->createInstance(); } - })); + }); } - - return collectAll(resultFutures).via(exe).then(); } void SingletonVault::destroyInstances() { diff --git a/folly/Singleton.h b/folly/Singleton.h index ffccd675..ac5b8328 100644 --- a/folly/Singleton.h +++ b/folly/Singleton.h @@ -109,7 +109,6 @@ #include #include #include -#include #include #include @@ -341,10 +340,8 @@ class SingletonVault { /** * Schedule eager singletons' initializations through the given executor. - * Return a future which is fulfilled after all the initialization functions - * complete. */ - Future doEagerInitVia(Executor* exe); + void doEagerInitVia(Executor* exe); // Destroy all singletons; when complete, the vault can't create // singletons once again until reenableInstances() is called. diff --git a/folly/test/SingletonTest.cpp b/folly/test/SingletonTest.cpp index fe14d2aa..5eff5cc1 100644 --- a/folly/test/SingletonTest.cpp +++ b/folly/test/SingletonTest.cpp @@ -459,9 +459,8 @@ TEST(Singleton, SingletonEagerInitAsync) { folly::EventBase eb; vault.registrationComplete(); EXPECT_FALSE(didEagerInit); - auto result = vault.doEagerInitVia(&eb); // a Future is returned + vault.doEagerInitVia(&eb); eb.loop(); - result.get(); // ensure this completed successfully and didn't hang forever EXPECT_TRUE(didEagerInit); sing.get_weak(); // (avoid compile error complaining about unused var 'sing') } @@ -538,7 +537,7 @@ TEST(Singleton, SingletonEagerInitParallel) { for (size_t j = 0; j < kThreads; j++) { threads.push_back(std::make_shared([&] { barrier.wait(); - vault.doEagerInitVia(&exe).get(); + vault.doEagerInitVia(&exe); })); } -- 2.34.1