Commit 0ab6e794 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Disallow InlineExecutor in coro::Task

Reviewed By: davidtgoldblatt

Differential Revision: D16530636

fbshipit-source-id: 0ea2b9b628f3c41f87a3d31e0b4c1dc71101f639
parent 665bff62
......@@ -67,10 +67,18 @@ class GlobalExecutor {
Function<std::unique_ptr<ExecutorBase>()> constructDefault_;
};
// aka InlineExecutor
class DefaultCPUExecutor : public Executor {
public:
FOLLY_NOINLINE void add(Func f) override {
f();
}
};
Singleton<GlobalExecutor<Executor>> gGlobalCPUExecutor([] {
return new GlobalExecutor<Executor>(
// Default global CPU executor is an InlineExecutor.
[] { return std::make_unique<InlineExecutor>(); });
[] { return std::make_unique<DefaultCPUExecutor>(); });
});
Singleton<GlobalExecutor<IOExecutor>> gGlobalIOExecutor([] {
......
......@@ -318,6 +318,15 @@ class FOLLY_NODISCARD TaskWithExecutor {
auto& promise = coro_.promise();
DCHECK(!promise.continuation_);
DCHECK(promise.executor_);
DCHECK(!dynamic_cast<folly::InlineExecutor*>(promise.executor_.get()))
<< "InlineExecutor is not safe and is not supported for coro::Task. "
<< "If you need to run a task inline in a unit-test, you should use "
<< "coro::blockingWait instead.";
DCHECK(!dynamic_cast<folly::QueuedImmediateExecutor*>(
promise.executor_.get()))
<< "QueuedImmediateExecutor is not safe and is not supported for coro::Task. "
<< "If you need to run a task inline in a unit-test, you should use "
<< "coro::blockingWait instead.";
promise.continuation_ = continuation;
promise.executor_->add(
......
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