From 502c8e4b9f082df107bd46170c3d38ce47a61a07 Mon Sep 17 00:00:00 2001 From: James Sedgwick Date: Mon, 12 Jan 2015 06:48:32 -0800 Subject: [PATCH] move Futures from folly::wangle to folly Summary: Namespace change. Next up is to extract the Executors into folly/executors/ Test Plan: wait for contbuild Reviewed By: davejwatson@fb.com Subscribers: jsedgwick, trunkagent, fbcode-common-diffs@, chaoyc, search-fbcode-diffs@, lars, davejwatson, ruibalp, hero-diffs@, zeus-diffs@, andrewcox, vikas, mcduff, cold-storage-diffs@, unicorn-diffs@, ldbrandy, targeting-diff-backend@, netego-diffs@, abirchall, fugalh, adamsyta, atlas2-eng@, chenzhimin, mpawlowski, alandau, bmatheny, adityab, everstore-dev@, zhuohuang, mwa, jgehring, prometheus-diffs@, smarlow, akr, bnitka, jcoens, benj, laser-diffs@, zhguo, jying, darshan, micha, apodsiadlo, alikhtarov, fuegen, dzhulgakov, jeremyfein, mshneer, folly-diffs@, wch, lins, tingy, hannesr, maxwellsayles FB internal diff: D1772779 Tasks: 5960242 Signature: t1:1772779:1420751149:bc0b9220be25f1d46d9cef3fdeaa9c3681217aff --- folly/futures/Future-inl.h | 8 +++---- folly/futures/Future.cpp | 4 ++-- folly/futures/Future.h | 4 ++-- folly/futures/InlineExecutor.h | 4 ++-- folly/futures/ManualExecutor.cpp | 4 ++-- folly/futures/ManualExecutor.h | 4 ++-- folly/futures/OpaqueCallbackShunt.h | 6 ++--- folly/futures/Promise-inl.h | 4 ++-- folly/futures/Promise.h | 4 ++-- folly/futures/QueuedImmediateExecutor.cpp | 4 ++-- folly/futures/QueuedImmediateExecutor.h | 4 ++-- folly/futures/README.md | 2 +- folly/futures/ScheduledExecutor.h | 4 ++-- folly/futures/Timekeeper.h | 24 +++++++++---------- folly/futures/Try-inl.h | 8 +++---- folly/futures/Try.h | 9 ++++--- folly/futures/WangleException.h | 4 ++-- folly/futures/detail/Core.h | 4 ++-- folly/futures/detail/FSM.h | 4 ++-- .../futures/detail/ThreadWheelTimekeeper.cpp | 4 ++-- folly/futures/detail/ThreadWheelTimekeeper.h | 4 ++-- folly/futures/detail/Types.h | 4 ++-- folly/futures/test/Benchmark.cpp | 2 +- folly/futures/test/ExecutorTest.cpp | 2 +- folly/futures/test/FSM.cpp | 2 +- folly/futures/test/FutureTest.cpp | 3 +-- folly/futures/test/Interrupts.cpp | 2 +- folly/futures/test/Thens.h | 2 +- folly/futures/test/TimekeeperTest.cpp | 10 ++++---- folly/futures/test/Try.cpp | 2 +- folly/futures/test/ViaTest.cpp | 2 +- folly/io/async/README.md | 2 +- folly/wangle/channel/AsyncSocketHandler.h | 12 +++++----- .../test/ThreadPoolExecutorTest.cpp | 1 + 34 files changed, 81 insertions(+), 82 deletions(-) diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index c19f08a0..b45545f9 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -23,7 +23,7 @@ #include #include -namespace folly { namespace wangle { +namespace folly { class Timekeeper; @@ -724,7 +724,7 @@ namespace { auto token = std::make_shared>(); folly::Baton<> baton; - folly::wangle::detail::getTimekeeperSingleton()->after(dur) + folly::detail::getTimekeeperSingleton()->after(dur) .then([&,token](Try const& t) { if (token->exchange(true) == false) { try { @@ -797,7 +797,7 @@ Future Future::within(Duration dur, E e, Timekeeper* tk) { auto ctx = std::make_shared(std::move(e)); if (!tk) { - tk = folly::wangle::detail::getTimekeeperSingleton(); + tk = folly::detail::getTimekeeperSingleton(); } tk->after(dur) @@ -834,7 +834,7 @@ Future Future::delayed(Duration dur, Timekeeper* tk) { }); } -}} +} // I haven't included a Future specialization because I don't forsee us // using it, however it is not difficult to add when needed. Refer to diff --git a/folly/futures/Future.cpp b/folly/futures/Future.cpp index fc7ff9b4..7d87a3fd 100644 --- a/folly/futures/Future.cpp +++ b/folly/futures/Future.cpp @@ -17,7 +17,7 @@ #include #include -namespace folly { namespace wangle { namespace futures { +namespace folly { namespace futures { Future sleep(Duration dur, Timekeeper* tk) { if (LIKELY(!tk)) { @@ -26,4 +26,4 @@ Future sleep(Duration dur, Timekeeper* tk) { return tk->after(dur); } -}}} +}} diff --git a/folly/futures/Future.h b/folly/futures/Future.h index e61c530c..494bf6e1 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -30,7 +30,7 @@ #include #include -namespace folly { namespace wangle { +namespace folly { template struct Promise; @@ -626,6 +626,6 @@ Future waitWithSemaphore(Future&& f); template Future waitWithSemaphore(Future&& f, Dur timeout); -}} // folly::wangle +} // folly #include diff --git a/folly/futures/InlineExecutor.h b/folly/futures/InlineExecutor.h index e6924085..2b5a07f3 100644 --- a/folly/futures/InlineExecutor.h +++ b/folly/futures/InlineExecutor.h @@ -17,7 +17,7 @@ #pragma once #include -namespace folly { namespace wangle { +namespace folly { /// When work is "queued", execute it immediately inline. /// Usually when you think you want this, you actually want a @@ -29,4 +29,4 @@ namespace folly { namespace wangle { } }; -}} +} diff --git a/folly/futures/ManualExecutor.cpp b/folly/futures/ManualExecutor.cpp index e75ae72a..c18476e5 100644 --- a/folly/futures/ManualExecutor.cpp +++ b/folly/futures/ManualExecutor.cpp @@ -22,7 +22,7 @@ #include -namespace folly { namespace wangle { +namespace folly { ManualExecutor::ManualExecutor() { if (sem_init(&sem_, 0, 0) == -1) { @@ -101,4 +101,4 @@ void ManualExecutor::advanceTo(TimePoint const& t) { run(); } -}} // namespace +} // folly diff --git a/folly/futures/ManualExecutor.h b/folly/futures/ManualExecutor.h index b17a0bde..db6a17da 100644 --- a/folly/futures/ManualExecutor.h +++ b/folly/futures/ManualExecutor.h @@ -22,7 +22,7 @@ #include #include -namespace folly { namespace wangle { +namespace folly { /// A ManualExecutor only does work when you turn the crank, by calling /// run() or indirectly with makeProgress() or waitFor(). /// @@ -117,4 +117,4 @@ namespace folly { namespace wangle { TimePoint now_ = now_.min(); }; -}} +} diff --git a/folly/futures/OpaqueCallbackShunt.h b/folly/futures/OpaqueCallbackShunt.h index 7977fb08..fae7a9c0 100644 --- a/folly/futures/OpaqueCallbackShunt.h +++ b/folly/futures/OpaqueCallbackShunt.h @@ -18,7 +18,7 @@ #include -namespace folly { namespace wangle { +namespace folly { /// These classes help you wrap an existing C style callback function /// into a Future. @@ -49,9 +49,9 @@ public: static_cast*>(arg)); handle->promise_.setValue(std::move(handle->obj_)); } - folly::wangle::Promise promise_; + folly::Promise promise_; private: T obj_; }; -}} // folly::wangle +} // folly diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index 75b260cc..044f94f1 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -22,7 +22,7 @@ #include #include -namespace folly { namespace wangle { +namespace folly { template Promise::Promise() : retrieved_(false), core_(new detail::Core()) @@ -136,4 +136,4 @@ void Promise::fulfil(F&& func) { fulfilTry(makeTryFunction(std::forward(func))); } -}} +} diff --git a/folly/futures/Promise.h b/folly/futures/Promise.h index 58b73230..192b1a79 100644 --- a/folly/futures/Promise.h +++ b/folly/futures/Promise.h @@ -20,7 +20,7 @@ #include #include -namespace folly { namespace wangle { +namespace folly { // forward declaration template class Future; @@ -102,7 +102,7 @@ private: void detach(); }; -}} +} #include #include diff --git a/folly/futures/QueuedImmediateExecutor.cpp b/folly/futures/QueuedImmediateExecutor.cpp index c9722878..f31d1d00 100644 --- a/folly/futures/QueuedImmediateExecutor.cpp +++ b/folly/futures/QueuedImmediateExecutor.cpp @@ -18,7 +18,7 @@ #include #include -namespace folly { namespace wangle { +namespace folly { void QueuedImmediateExecutor::add(Func callback) { thread_local std::queue q; @@ -34,4 +34,4 @@ void QueuedImmediateExecutor::add(Func callback) { } } -}} // namespace +} // namespace diff --git a/folly/futures/QueuedImmediateExecutor.h b/folly/futures/QueuedImmediateExecutor.h index a82c32db..73b7225a 100644 --- a/folly/futures/QueuedImmediateExecutor.h +++ b/folly/futures/QueuedImmediateExecutor.h @@ -18,7 +18,7 @@ #include -namespace folly { namespace wangle { +namespace folly { /** * Runs inline like InlineExecutor, but with a queue so that any tasks added @@ -30,4 +30,4 @@ class QueuedImmediateExecutor : public Executor { void add(Func) override; }; -}} // namespace +} // folly diff --git a/folly/futures/README.md b/folly/futures/README.md index cec17f56..633b7438 100644 --- a/folly/futures/README.md +++ b/folly/futures/README.md @@ -19,7 +19,7 @@ The primary semantic differences are that Wangle Futures and Promises are not th ```C++ #include -using namespace folly::wangle; +using namespace folly; using namespace std; void foo(int x) { diff --git a/folly/futures/ScheduledExecutor.h b/folly/futures/ScheduledExecutor.h index 94850c28..a3f6dedb 100644 --- a/folly/futures/ScheduledExecutor.h +++ b/folly/futures/ScheduledExecutor.h @@ -21,7 +21,7 @@ #include #include -namespace folly { namespace wangle { +namespace folly { // An executor that supports timed scheduling. Like RxScheduler. class ScheduledExecutor : public Executor { public: @@ -54,4 +54,4 @@ namespace folly { namespace wangle { return std::chrono::steady_clock::now(); } }; -}} +} diff --git a/folly/futures/Timekeeper.h b/folly/futures/Timekeeper.h index 7bbdddc5..07c0c41d 100644 --- a/folly/futures/Timekeeper.h +++ b/folly/futures/Timekeeper.h @@ -18,7 +18,7 @@ #include -namespace folly { namespace wangle { +namespace folly { template struct Future; @@ -68,23 +68,23 @@ class Timekeeper { Future at(std::chrono::time_point when); }; -}} +} // namespace folly // now get those definitions #include // finally we can use Future -namespace folly { namespace wangle { +namespace folly { - template - Future Timekeeper::at(std::chrono::time_point when) { - auto now = Clock::now(); - - if (when <= now) { - return makeFuture(); - } +template +Future Timekeeper::at(std::chrono::time_point when) { + auto now = Clock::now(); - return after(when - now); + if (when <= now) { + return makeFuture(); } -}} + return after(when - now); +} + +} // namespace folly diff --git a/folly/futures/Try-inl.h b/folly/futures/Try-inl.h index 0aded746..05cb4cce 100644 --- a/folly/futures/Try-inl.h +++ b/folly/futures/Try-inl.h @@ -20,7 +20,7 @@ #include -namespace folly { namespace wangle { +namespace folly { template Try::Try(Try&& t) : contains_(t.contains_) { @@ -82,11 +82,11 @@ void Try::throwIfFailed() const { } template -inline T moveFromTry(wangle::Try&& t) { +inline T moveFromTry(Try&& t) { return std::move(t.value()); } -inline void moveFromTry(wangle::Try&& t) { +inline void moveFromTry(Try&& t) { return t.value(); } @@ -120,4 +120,4 @@ makeTryFunction(F&& f) { } } -}} +} // folly diff --git a/folly/futures/Try.h b/folly/futures/Try.h index e98682d6..988bf2e8 100644 --- a/folly/futures/Try.h +++ b/folly/futures/Try.h @@ -25,7 +25,7 @@ #include #include -namespace folly { namespace wangle { +namespace folly { /* * Try is a wrapper that contains either an instance of T, an exception, or @@ -313,14 +313,14 @@ class Try { * @returns value contained in t */ template -T moveFromTry(wangle::Try&& t); +T moveFromTry(Try&& t); /* * Throws if try contained an exception. * * @param t Try to move from */ -void moveFromTry(wangle::Try&& t); +void moveFromTry(Try&& t); /* * @param f a function to execute and capture the result of (value or exception) @@ -346,7 +346,6 @@ typename std::enable_if< Try>::type makeTryFunction(F&& f); - -}} +} // folly #include diff --git a/folly/futures/WangleException.h b/folly/futures/WangleException.h index 0d971303..bfbbf39f 100644 --- a/folly/futures/WangleException.h +++ b/folly/futures/WangleException.h @@ -19,7 +19,7 @@ #include #include -namespace folly { namespace wangle { +namespace folly { class WangleException : public std::exception { @@ -91,4 +91,4 @@ class TimedOut : public WangleException { TimedOut() : WangleException("Timed out") {} }; -}} +} diff --git a/folly/futures/detail/Core.h b/folly/futures/detail/Core.h index 1eb7062c..0c39212d 100644 --- a/folly/futures/detail/Core.h +++ b/folly/futures/detail/Core.h @@ -32,7 +32,7 @@ #include -namespace folly { namespace wangle { namespace detail { +namespace folly { namespace detail { // As of GCC 4.8.1, the std::function in libstdc++ optimizes only for pointers // to functions, using a helper avoids a call to malloc. @@ -289,4 +289,4 @@ struct WhenAnyContext { } }; -}}} // namespace +}} // folly::detail diff --git a/folly/futures/detail/FSM.h b/folly/futures/detail/FSM.h index be4eb8ae..997b6c21 100644 --- a/folly/futures/detail/FSM.h +++ b/folly/futures/detail/FSM.h @@ -20,7 +20,7 @@ #include #include -namespace folly { namespace wangle { namespace detail { +namespace folly { namespace detail { /// Finite State Machine helper base class. /// Inherit from this. @@ -119,4 +119,4 @@ public: #define FSM_END }}} -}}} +}} // folly::detail diff --git a/folly/futures/detail/ThreadWheelTimekeeper.cpp b/folly/futures/detail/ThreadWheelTimekeeper.cpp index d77e68e9..28ae72de 100644 --- a/folly/futures/detail/ThreadWheelTimekeeper.cpp +++ b/folly/futures/detail/ThreadWheelTimekeeper.cpp @@ -19,7 +19,7 @@ #include #include -namespace folly { namespace wangle { namespace detail { +namespace folly { namespace detail { namespace { Singleton timekeeperSingleton_; @@ -90,4 +90,4 @@ Timekeeper* getTimekeeperSingleton() { return timekeeperSingleton_.get_fast(); } -}}} +}} // folly::detail diff --git a/folly/futures/detail/ThreadWheelTimekeeper.h b/folly/futures/detail/ThreadWheelTimekeeper.h index 1174dceb..33b1261f 100644 --- a/folly/futures/detail/ThreadWheelTimekeeper.h +++ b/folly/futures/detail/ThreadWheelTimekeeper.h @@ -22,7 +22,7 @@ #include #include -namespace folly { namespace wangle { namespace detail { +namespace folly { namespace detail { /// The default Timekeeper implementation which uses a HHWheelTimer on an /// EventBase in a dedicated thread. Users needn't deal with this directly, it @@ -47,4 +47,4 @@ class ThreadWheelTimekeeper : public Timekeeper { Timekeeper* getTimekeeperSingleton(); -}}} +}} // folly::detail diff --git a/folly/futures/detail/Types.h b/folly/futures/detail/Types.h index 57b93e05..873a591f 100644 --- a/folly/futures/detail/Types.h +++ b/folly/futures/detail/Types.h @@ -18,8 +18,8 @@ #include -namespace folly { namespace wangle { +namespace folly { using Duration = std::chrono::milliseconds; -}} +} diff --git a/folly/futures/test/Benchmark.cpp b/folly/futures/test/Benchmark.cpp index 0f73d3f1..c6f88bdc 100644 --- a/folly/futures/test/Benchmark.cpp +++ b/folly/futures/test/Benchmark.cpp @@ -22,7 +22,7 @@ #include #include -using namespace folly::wangle; +using namespace folly; using namespace std; namespace { diff --git a/folly/futures/test/ExecutorTest.cpp b/folly/futures/test/ExecutorTest.cpp index 2e9a3f6a..a9bfef4b 100644 --- a/folly/futures/test/ExecutorTest.cpp +++ b/folly/futures/test/ExecutorTest.cpp @@ -21,7 +21,7 @@ #include #include -using namespace folly::wangle; +using namespace folly; using namespace std::chrono; using namespace testing; diff --git a/folly/futures/test/FSM.cpp b/folly/futures/test/FSM.cpp index e4fef36b..4f4710f5 100644 --- a/folly/futures/test/FSM.cpp +++ b/folly/futures/test/FSM.cpp @@ -17,7 +17,7 @@ #include #include -using namespace folly::wangle::detail; +using namespace folly::detail; enum class State { A, B }; diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index c135bf2f..cbb94472 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -32,7 +32,6 @@ #include using namespace folly; -using namespace folly::wangle; using std::pair; using std::string; using std::unique_ptr; @@ -1187,7 +1186,7 @@ TEST(Future, CircularDependencySharedPtrSelfReset) { auto ptr = std::make_shared>(promise.getFuture()); ptr->then( - [ptr] (folly::wangle::Try&& uid) mutable { + [ptr] (folly::Try&& uid) mutable { EXPECT_EQ(1, ptr.use_count()); // Leaving no references to ourselves. diff --git a/folly/futures/test/Interrupts.cpp b/folly/futures/test/Interrupts.cpp index d4a35a75..7ef88f70 100644 --- a/folly/futures/test/Interrupts.cpp +++ b/folly/futures/test/Interrupts.cpp @@ -19,7 +19,7 @@ #include #include -using namespace folly::wangle; +using namespace folly; using folly::exception_wrapper; TEST(Interrupts, raise) { diff --git a/folly/futures/test/Thens.h b/folly/futures/test/Thens.h index d65d914f..e8e8a8e5 100644 --- a/folly/futures/test/Thens.h +++ b/folly/futures/test/Thens.h @@ -20,7 +20,7 @@ #include #include -using namespace folly::wangle; +using namespace folly; using namespace std; using namespace testing; diff --git a/folly/futures/test/TimekeeperTest.cpp b/folly/futures/test/TimekeeperTest.cpp index 2ede4673..c3e53d35 100644 --- a/folly/futures/test/TimekeeperTest.cpp +++ b/folly/futures/test/TimekeeperTest.cpp @@ -18,10 +18,10 @@ #include #include -using namespace folly::wangle; +using namespace folly; using namespace std::chrono; -using folly::wangle::Timekeeper; -using Duration = folly::wangle::Duration; +using folly::Timekeeper; +using Duration = folly::Duration; std::chrono::milliseconds const one_ms(1); std::chrono::milliseconds const awhile(10); @@ -32,7 +32,7 @@ std::chrono::steady_clock::time_point now() { struct TimekeeperFixture : public testing::Test { TimekeeperFixture() : - timeLord_(folly::wangle::detail::getTimekeeperSingleton()) + timeLord_(folly::detail::getTimekeeperSingleton()) {} Timekeeper* timeLord_; @@ -71,7 +71,7 @@ TEST(Timekeeper, futureGetBeforeTimeout) { TEST(Timekeeper, futureGetTimeout) { Promise p; - EXPECT_THROW(p.getFuture().get(Duration(1)), folly::wangle::TimedOut); + EXPECT_THROW(p.getFuture().get(Duration(1)), folly::TimedOut); } TEST(Timekeeper, futureSleep) { diff --git a/folly/futures/test/Try.cpp b/folly/futures/test/Try.cpp index 5846f628..db42aa59 100644 --- a/folly/futures/test/Try.cpp +++ b/folly/futures/test/Try.cpp @@ -19,7 +19,7 @@ #include #include -using namespace folly::wangle; +using namespace folly; TEST(Try, makeTryFunction) { auto func = []() { diff --git a/folly/futures/test/ViaTest.cpp b/folly/futures/test/ViaTest.cpp index d940e10e..2bbd89f0 100644 --- a/folly/futures/test/ViaTest.cpp +++ b/folly/futures/test/ViaTest.cpp @@ -21,7 +21,7 @@ #include #include -using namespace folly::wangle; +using namespace folly; struct ManualWaiter { explicit ManualWaiter(std::shared_ptr ex) : ex(ex) {} diff --git a/folly/io/async/README.md b/folly/io/async/README.md index 3b09dd17..e116c83b 100644 --- a/folly/io/async/README.md +++ b/folly/io/async/README.md @@ -281,7 +281,7 @@ threads. Major uses for this include: In this library only runInEventBaseThread save/restores the request context, although other Facebook libraries that pass requests between -threads do also: folly::wangle::future, and fbthrift::ThreadManager, etc +threads do also: folly::future, and fbthrift::ThreadManager, etc ### DelayedDestruction diff --git a/folly/wangle/channel/AsyncSocketHandler.h b/folly/wangle/channel/AsyncSocketHandler.h index eb47cb05..46fb03b8 100644 --- a/folly/wangle/channel/AsyncSocketHandler.h +++ b/folly/wangle/channel/AsyncSocketHandler.h @@ -69,16 +69,16 @@ class AsyncSocketHandler ctx_ = ctx; } - folly::wangle::Future write( + folly::Future write( Context* ctx, std::unique_ptr buf) override { if (UNLIKELY(!buf)) { - return folly::wangle::makeFuture(); + return folly::makeFuture(); } if (!socket_->good()) { VLOG(5) << "socket is closed in write()"; - return folly::wangle::makeFuture(AsyncSocketException( + return folly::makeFuture(AsyncSocketException( AsyncSocketException::AsyncSocketExceptionType::NOT_OPEN, "socket is closed in write()")); } @@ -89,12 +89,12 @@ class AsyncSocketHandler return future; }; - folly::wangle::Future close(Context* ctx) { + folly::Future close(Context* ctx) { if (socket_) { detachReadCallback(); socket_->closeNow(); } - return folly::wangle::makeFuture(); + return folly::makeFuture(); } // Must override to avoid warnings about hidden overloaded virtual due to @@ -142,7 +142,7 @@ class AsyncSocketHandler private: friend class AsyncSocketHandler; - folly::wangle::Promise promise_; + folly::Promise promise_; }; Context* ctx_{nullptr}; diff --git a/folly/wangle/concurrent/test/ThreadPoolExecutorTest.cpp b/folly/wangle/concurrent/test/ThreadPoolExecutorTest.cpp index b83dce28..d08d2e50 100644 --- a/folly/wangle/concurrent/test/ThreadPoolExecutorTest.cpp +++ b/folly/wangle/concurrent/test/ThreadPoolExecutorTest.cpp @@ -21,6 +21,7 @@ #include #include +using namespace folly; using namespace folly::wangle; using namespace std::chrono; -- 2.34.1