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
#include <folly/futures/detail/Core.h>
#include <folly/futures/Timekeeper.h>
-namespace folly { namespace wangle {
+namespace folly {
class Timekeeper;
auto token = std::make_shared<std::atomic<bool>>();
folly::Baton<> baton;
- folly::wangle::detail::getTimekeeperSingleton()->after(dur)
+ folly::detail::getTimekeeperSingleton()->after(dur)
.then([&,token](Try<void> const& t) {
if (token->exchange(true) == false) {
try {
auto ctx = std::make_shared<Context>(std::move(e));
if (!tk) {
- tk = folly::wangle::detail::getTimekeeperSingleton();
+ tk = folly::detail::getTimekeeperSingleton();
}
tk->after(dur)
});
}
-}}
+}
// I haven't included a Future<T&> specialization because I don't forsee us
// using it, however it is not difficult to add when needed. Refer to
#include <folly/futures/detail/ThreadWheelTimekeeper.h>
#include <folly/Likely.h>
-namespace folly { namespace wangle { namespace futures {
+namespace folly { namespace futures {
Future<void> sleep(Duration dur, Timekeeper* tk) {
if (LIKELY(!tk)) {
return tk->after(dur);
}
-}}}
+}}
#include <folly/futures/WangleException.h>
#include <folly/futures/detail/Types.h>
-namespace folly { namespace wangle {
+namespace folly {
template <class> struct Promise;
template <typename T, class Dur>
Future<T> waitWithSemaphore(Future<T>&& f, Dur timeout);
-}} // folly::wangle
+} // folly
#include <folly/futures/Future-inl.h>
#pragma once
#include <folly/Executor.h>
-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
}
};
-}}
+}
#include <stdexcept>
-namespace folly { namespace wangle {
+namespace folly {
ManualExecutor::ManualExecutor() {
if (sem_init(&sem_, 0, 0) == -1) {
run();
}
-}} // namespace
+} // folly
#include <queue>
#include <cstdio>
-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().
///
TimePoint now_ = now_.min();
};
-}}
+}
#include <folly/futures/Promise.h>
-namespace folly { namespace wangle {
+namespace folly {
/// These classes help you wrap an existing C style callback function
/// into a Future.
static_cast<OpaqueCallbackShunt<T>*>(arg));
handle->promise_.setValue(std::move(handle->obj_));
}
- folly::wangle::Promise<T> promise_;
+ folly::Promise<T> promise_;
private:
T obj_;
};
-}} // folly::wangle
+} // folly
#include <folly/futures/WangleException.h>
#include <folly/futures/detail/Core.h>
-namespace folly { namespace wangle {
+namespace folly {
template <class T>
Promise<T>::Promise() : retrieved_(false), core_(new detail::Core<T>())
fulfilTry(makeTryFunction(std::forward<F>(func)));
}
-}}
+}
#include <folly/futures/Try.h>
#include <functional>
-namespace folly { namespace wangle {
+namespace folly {
// forward declaration
template <class T> class Future;
void detach();
};
-}}
+}
#include <folly/futures/Future.h>
#include <folly/futures/Promise-inl.h>
#include <folly/ThreadLocal.h>
#include <queue>
-namespace folly { namespace wangle {
+namespace folly {
void QueuedImmediateExecutor::add(Func callback) {
thread_local std::queue<Func> q;
}
}
-}} // namespace
+} // namespace
#include <folly/Executor.h>
-namespace folly { namespace wangle {
+namespace folly {
/**
* Runs inline like InlineExecutor, but with a queue so that any tasks added
void add(Func) override;
};
-}} // namespace
+} // folly
```C++
#include <folly/futures/Future.h>
-using namespace folly::wangle;
+using namespace folly;
using namespace std;
void foo(int x) {
#include <memory>
#include <stdexcept>
-namespace folly { namespace wangle {
+namespace folly {
// An executor that supports timed scheduling. Like RxScheduler.
class ScheduledExecutor : public Executor {
public:
return std::chrono::steady_clock::now();
}
};
-}}
+}
#include <folly/futures/detail/Types.h>
-namespace folly { namespace wangle {
+namespace folly {
template <class> struct Future;
Future<void> at(std::chrono::time_point<Clock> when);
};
-}}
+} // namespace folly
// now get those definitions
#include <folly/futures/Future.h>
// finally we can use Future
-namespace folly { namespace wangle {
+namespace folly {
- template <class Clock>
- Future<void> Timekeeper::at(std::chrono::time_point<Clock> when) {
- auto now = Clock::now();
-
- if (when <= now) {
- return makeFuture();
- }
+template <class Clock>
+Future<void> Timekeeper::at(std::chrono::time_point<Clock> when) {
+ auto now = Clock::now();
- return after(when - now);
+ if (when <= now) {
+ return makeFuture();
}
-}}
+ return after(when - now);
+}
+
+} // namespace folly
#include <folly/futures/WangleException.h>
-namespace folly { namespace wangle {
+namespace folly {
template <class T>
Try<T>::Try(Try<T>&& t) : contains_(t.contains_) {
}
template <typename T>
-inline T moveFromTry(wangle::Try<T>&& t) {
+inline T moveFromTry(Try<T>&& t) {
return std::move(t.value());
}
-inline void moveFromTry(wangle::Try<void>&& t) {
+inline void moveFromTry(Try<void>&& t) {
return t.value();
}
}
}
-}}
+} // folly
#include <folly/futures/Deprecated.h>
#include <folly/futures/WangleException.h>
-namespace folly { namespace wangle {
+namespace folly {
/*
* Try<T> is a wrapper that contains either an instance of T, an exception, or
* @returns value contained in t
*/
template <typename T>
-T moveFromTry(wangle::Try<T>&& t);
+T moveFromTry(Try<T>&& t);
/*
* Throws if try contained an exception.
*
* @param t Try to move from
*/
-void moveFromTry(wangle::Try<void>&& t);
+void moveFromTry(Try<void>&& t);
/*
* @param f a function to execute and capture the result of (value or exception)
Try<void>>::type
makeTryFunction(F&& f);
-
-}}
+} // folly
#include <folly/futures/Try-inl.h>
#include <exception>
#include <string>
-namespace folly { namespace wangle {
+namespace folly {
class WangleException : public std::exception {
TimedOut() : WangleException("Timed out") {}
};
-}}
+}
#include <folly/io/async/Request.h>
-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.
}
};
-}}} // namespace
+}} // folly::detail
#include <mutex>
#include <folly/SmallLocks.h>
-namespace folly { namespace wangle { namespace detail {
+namespace folly { namespace detail {
/// Finite State Machine helper base class.
/// Inherit from this.
#define FSM_END }}}
-}}}
+}} // folly::detail
#include <folly/futures/Future.h>
#include <future>
-namespace folly { namespace wangle { namespace detail {
+namespace folly { namespace detail {
namespace {
Singleton<ThreadWheelTimekeeper> timekeeperSingleton_;
return timekeeperSingleton_.get_fast();
}
-}}}
+}} // folly::detail
#include <folly/io/async/HHWheelTimer.h>
#include <thread>
-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
Timekeeper* getTimekeeperSingleton();
-}}}
+}} // folly::detail
#include <chrono>
-namespace folly { namespace wangle {
+namespace folly {
using Duration = std::chrono::milliseconds;
-}}
+}
#include <semaphore.h>
#include <vector>
-using namespace folly::wangle;
+using namespace folly;
using namespace std;
namespace {
#include <folly/futures/Future.h>
#include <folly/Baton.h>
-using namespace folly::wangle;
+using namespace folly;
using namespace std::chrono;
using namespace testing;
#include <gtest/gtest.h>
#include <folly/futures/detail/FSM.h>
-using namespace folly::wangle::detail;
+using namespace folly::detail;
enum class State { A, B };
#include <folly/io/async/Request.h>
using namespace folly;
-using namespace folly::wangle;
using std::pair;
using std::string;
using std::unique_ptr;
auto ptr = std::make_shared<Future<int64_t>>(promise.getFuture());
ptr->then(
- [ptr] (folly::wangle::Try<int64_t>&& uid) mutable {
+ [ptr] (folly::Try<int64_t>&& uid) mutable {
EXPECT_EQ(1, ptr.use_count());
// Leaving no references to ourselves.
#include <folly/futures/Future.h>
#include <folly/futures/Promise.h>
-using namespace folly::wangle;
+using namespace folly;
using folly::exception_wrapper;
TEST(Interrupts, raise) {
#include <folly/futures/Future.h>
#include <folly/Executor.h>
-using namespace folly::wangle;
+using namespace folly;
using namespace std;
using namespace testing;
#include <folly/futures/Timekeeper.h>
#include <unistd.h>
-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);
struct TimekeeperFixture : public testing::Test {
TimekeeperFixture() :
- timeLord_(folly::wangle::detail::getTimekeeperSingleton())
+ timeLord_(folly::detail::getTimekeeperSingleton())
{}
Timekeeper* timeLord_;
TEST(Timekeeper, futureGetTimeout) {
Promise<int> p;
- EXPECT_THROW(p.getFuture().get(Duration(1)), folly::wangle::TimedOut);
+ EXPECT_THROW(p.getFuture().get(Duration(1)), folly::TimedOut);
}
TEST(Timekeeper, futureSleep) {
#include <folly/Memory.h>
#include <folly/futures/Try.h>
-using namespace folly::wangle;
+using namespace folly;
TEST(Try, makeTryFunction) {
auto func = []() {
#include <folly/futures/InlineExecutor.h>
#include <folly/futures/ManualExecutor.h>
-using namespace folly::wangle;
+using namespace folly;
struct ManualWaiter {
explicit ManualWaiter(std::shared_ptr<ManualExecutor> ex) : ex(ex) {}
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
ctx_ = ctx;
}
- folly::wangle::Future<void> write(
+ folly::Future<void> write(
Context* ctx,
std::unique_ptr<folly::IOBuf> 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<void>(AsyncSocketException(
+ return folly::makeFuture<void>(AsyncSocketException(
AsyncSocketException::AsyncSocketExceptionType::NOT_OPEN,
"socket is closed in write()"));
}
return future;
};
- folly::wangle::Future<void> close(Context* ctx) {
+ folly::Future<void> 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
private:
friend class AsyncSocketHandler;
- folly::wangle::Promise<void> promise_;
+ folly::Promise<void> promise_;
};
Context* ctx_{nullptr};
#include <glog/logging.h>
#include <gtest/gtest.h>
+using namespace folly;
using namespace folly::wangle;
using namespace std::chrono;