2018-08-03 23:08:37 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-08-03 23:08:37 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2018-08-03 23:08:37 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2018-08-03 23:08:37 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <folly/Executor.h>
|
|
|
|
#include <folly/Range.h>
|
|
|
|
|
|
|
|
namespace folly {
|
|
|
|
class ManualExecutor;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An Executor that is guaranteed to never block, nor throw (except OOM), nor
|
|
|
|
* execute inline from `add()`.
|
|
|
|
*
|
|
|
|
* Parts of Eden rely on queuing a function to be non-blocking for deadlock
|
|
|
|
* safety.
|
|
|
|
*/
|
|
|
|
class UnboundedQueueExecutor : public folly::Executor {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Instantiates with a folly::CPUThreadPoolExecutor with the given threadCount
|
|
|
|
* and threadNamePrefix but with an unlimited queue.
|
|
|
|
*/
|
|
|
|
explicit UnboundedQueueExecutor(
|
|
|
|
size_t threadCount,
|
|
|
|
folly::StringPiece threadNamePrefix);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ManualExecutors are unbounded too.
|
|
|
|
*
|
|
|
|
* Used primarily for tests.
|
|
|
|
*/
|
|
|
|
explicit UnboundedQueueExecutor(
|
2018-08-21 22:10:21 +03:00
|
|
|
std::shared_ptr<folly::ManualExecutor> executor);
|
2018-08-03 23:08:37 +03:00
|
|
|
|
|
|
|
UnboundedQueueExecutor(const UnboundedQueueExecutor&) = delete;
|
|
|
|
UnboundedQueueExecutor& operator=(const UnboundedQueueExecutor&) = delete;
|
|
|
|
UnboundedQueueExecutor(UnboundedQueueExecutor&&) = delete;
|
|
|
|
UnboundedQueueExecutor& operator=(UnboundedQueueExecutor&&) = delete;
|
|
|
|
|
|
|
|
void add(folly::Func func) override {
|
|
|
|
executor_->add(std::move(func));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-08-21 22:10:21 +03:00
|
|
|
std::shared_ptr<folly::Executor> executor_;
|
2018-08-03 23:08:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|