23 dynamic_cputhreadpoolexecutor,
25 "CPUThreadPoolExecutor will dynamically create and destroy threads");
34 std::shared_ptr<ThreadFactory> threadFactory)
37 FLAGS_dynamic_cputhreadpoolexecutor ? 0 : numThreads,
39 taskQueue_(
std::
move(taskQueue)) {
46 std::shared_ptr<ThreadFactory> threadFactory)
57 std::shared_ptr<ThreadFactory> threadFactory)
66 std::shared_ptr<ThreadFactory> threadFactory)
81 std::shared_ptr<ThreadFactory> threadFactory)
93 std::shared_ptr<ThreadFactory> threadFactory)
113 Func expireCallback) {
116 if (!result.reusedThread) {
122 add(
std::move(func), priority, std::chrono::milliseconds(0));
129 Func expireCallback) {
134 if (!result.reusedThread) {
177 thread->startupBaton.post();
182 if (
UNLIKELY(!task || task.value().poison)) {
187 o->threadStopped(thread.get());
212 for (
size_t i = 0;
i < n;
i++) {
static void runTask(const ThreadPtr &thread, Task &&task)
void addWithPriority(Func func, int8_t priority) override
std::unique_ptr< BlockingQueue< CPUTask > > taskQueue_
SharedMutex threadListLock_
std::chrono::milliseconds threadTimeout_
static const int8_t LO_PRI
constexpr detail::Map< Move > move
folly::ThreadPoolListHook threadPoolHook_
void stopThreads(size_t n) override
uint8_t getNumPriorities() const override
—— Concurrent Priority Queue Implementation ——
std::shared_ptr< Thread > ThreadPtr
std::atomic< bool > isJoin_
size_t getTaskQueueSize() const
bool taskShouldStop(folly::Optional< CPUTask > &)
BlockingQueue< CPUTask > * getTaskQueue()
std::vector< std::shared_ptr< Observer > > observers_
void remove(const ThreadPtr &state)
~CPUThreadPoolExecutor() override
void threadRun(ThreadPtr thread) override
DEFINE_bool(dynamic_cputhreadpoolexecutor, true,"CPUThreadPoolExecutor will dynamically create and destroy threads")
void add(Func func) override
void setNumThreads(size_t numThreads)
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
void ensureActiveThreads()
BlockingQueueAddResult add(ThreadPtr item) override
StoppedThreadQueue stoppedThreads_
CPUThreadPoolExecutor(size_t numThreads, std::unique_ptr< BlockingQueue< CPUTask >> taskQueue, std::shared_ptr< ThreadFactory > threadFactory=std::make_shared< NamedThreadFactory >("CPUThreadPool"))
static const size_t kDefaultMaxQueueSize
size_t getPendingTaskCountImpl() override
std::atomic< ssize_t > threadsToStop_
constexpr detail::First first