|
proxygen
|
#include <CPUThreadPoolExecutor.h>
Classes | |
| struct | CPUTask |
Public Member Functions | |
| CPUThreadPoolExecutor (size_t numThreads, std::unique_ptr< BlockingQueue< CPUTask >> taskQueue, std::shared_ptr< ThreadFactory > threadFactory=std::make_shared< NamedThreadFactory >("CPUThreadPool")) | |
| CPUThreadPoolExecutor (std::pair< size_t, size_t > numThreads, std::unique_ptr< BlockingQueue< CPUTask >> taskQueue, std::shared_ptr< ThreadFactory > threadFactory=std::make_shared< NamedThreadFactory >("CPUThreadPool")) | |
| CPUThreadPoolExecutor (size_t numThreads) | |
| CPUThreadPoolExecutor (size_t numThreads, std::shared_ptr< ThreadFactory > threadFactory) | |
| CPUThreadPoolExecutor (std::pair< size_t, size_t > numThreads, std::shared_ptr< ThreadFactory > threadFactory) | |
| CPUThreadPoolExecutor (size_t numThreads, int8_t numPriorities, std::shared_ptr< ThreadFactory > threadFactory=std::make_shared< NamedThreadFactory >("CPUThreadPool")) | |
| CPUThreadPoolExecutor (size_t numThreads, int8_t numPriorities, size_t maxQueueSize, std::shared_ptr< ThreadFactory > threadFactory=std::make_shared< NamedThreadFactory >("CPUThreadPool")) | |
| ~CPUThreadPoolExecutor () override | |
| void | add (Func func) override |
| void | add (Func func, std::chrono::milliseconds expiration, Func expireCallback=nullptr) override |
| void | addWithPriority (Func func, int8_t priority) override |
| void | add (Func func, int8_t priority, std::chrono::milliseconds expiration, Func expireCallback=nullptr) |
| size_t | getTaskQueueSize () const |
| uint8_t | getNumPriorities () const override |
Public Member Functions inherited from folly::ThreadPoolExecutor | |
| ThreadPoolExecutor (size_t maxThreads, size_t minThreads, std::shared_ptr< ThreadFactory > threadFactory, bool isWaitForAll=false) | |
| ~ThreadPoolExecutor () override | |
| void | setThreadFactory (std::shared_ptr< ThreadFactory > threadFactory) |
| std::shared_ptr< ThreadFactory > | getThreadFactory () |
| size_t | numThreads () |
| void | setNumThreads (size_t numThreads) |
| size_t | numActiveThreads () |
| void | stop () |
| void | join () |
| PoolStats | getPoolStats () |
| size_t | getPendingTaskCount () |
| std::string | getName () |
| void | subscribeToTaskStats (TaskStatsCallback cb) |
| void | addObserver (std::shared_ptr< Observer >) |
| void | removeObserver (std::shared_ptr< Observer >) |
| void | setThreadDeathTimeout (std::chrono::milliseconds timeout) |
Public Member Functions inherited from folly::DefaultKeepAliveExecutor | |
| DefaultKeepAliveExecutor () | |
| virtual | ~DefaultKeepAliveExecutor () |
| folly::Executor::KeepAlive | weakRef () |
Public Member Functions inherited from folly::Executor | |
| virtual | ~Executor () |
Static Public Attributes | |
| static const size_t | kDefaultMaxQueueSize = 1 << 14 |
Static Public Attributes inherited from folly::Executor | |
| static const int8_t | LO_PRI = SCHAR_MIN |
| static const int8_t | MID_PRI = 0 |
| static const int8_t | HI_PRI = SCHAR_MAX |
Protected Member Functions | |
| BlockingQueue< CPUTask > * | getTaskQueue () |
Protected Member Functions inherited from folly::ThreadPoolExecutor | |
| void | addThreads (size_t n) |
| void | removeThreads (size_t n, bool isJoin) |
| void | joinStoppedThreads (size_t n) |
| virtual ThreadPtr | makeThread () |
| void | ensureActiveThreads () |
| void | ensureJoined () |
| bool | minActive () |
| bool | tryTimeoutThread () |
| void | joinKeepAliveOnce () |
Protected Member Functions inherited from folly::DefaultKeepAliveExecutor | |
| void | joinKeepAlive () |
Private Member Functions | |
| void | threadRun (ThreadPtr thread) override |
| void | stopThreads (size_t n) override |
| size_t | getPendingTaskCountImpl () override |
| bool | tryDecrToStop () |
| bool | taskShouldStop (folly::Optional< CPUTask > &) |
Private Attributes | |
| std::unique_ptr< BlockingQueue< CPUTask > > | taskQueue_ |
| std::atomic< ssize_t > | threadsToStop_ {0} |
Additional Inherited Members | |
Public Types inherited from folly::ThreadPoolExecutor | |
| using | TaskStatsCallback = std::function< void(TaskStats)> |
Static Public Member Functions inherited from folly::ThreadPoolExecutor | |
| static void | withAll (FunctionRef< void(ThreadPoolExecutor &)> f) |
Static Public Member Functions inherited from folly::Executor | |
| template<typename ExecutorT > | |
| static KeepAlive< ExecutorT > | getKeepAliveToken (ExecutorT *executor) |
| template<typename ExecutorT > | |
| static KeepAlive< ExecutorT > | getKeepAliveToken (ExecutorT &executor) |
Protected Types inherited from folly::ThreadPoolExecutor | |
| typedef std::shared_ptr< Thread > | ThreadPtr |
Static Protected Member Functions inherited from folly::ThreadPoolExecutor | |
| static void | runTask (const ThreadPtr &thread, Task &&task) |
Static Protected Member Functions inherited from folly::Executor | |
| template<typename ExecutorT > | |
| static bool | isKeepAliveDummy (const KeepAlive< ExecutorT > &keepAlive) |
| template<typename ExecutorT > | |
| static KeepAlive< ExecutorT > | makeKeepAlive (ExecutorT *executor) |
Protected Attributes inherited from folly::ThreadPoolExecutor | |
| std::shared_ptr< ThreadFactory > | threadFactory_ |
| const bool | isWaitForAll_ |
| ThreadList | threadList_ |
| SharedMutex | threadListLock_ |
| StoppedThreadQueue | stoppedThreads_ |
| std::atomic< bool > | isJoin_ {false} |
| std::shared_ptr< TaskStatsCallbackRegistry > | taskStatsCallbacks_ |
| std::vector< std::shared_ptr< Observer > > | observers_ |
| folly::ThreadPoolListHook | threadPoolHook_ |
| std::atomic< size_t > | maxThreads_ {0} |
| std::atomic< size_t > | minThreads_ {0} |
| std::atomic< size_t > | activeThreads_ {0} |
| std::atomic< size_t > | threadsToJoin_ {0} |
| std::chrono::milliseconds | threadTimeout_ {0} |
| bool | keepAliveJoined_ {false} |
A Thread pool for CPU bound tasks.
Definition at line 63 of file CPUThreadPoolExecutor.h.
| folly::CPUThreadPoolExecutor::CPUThreadPoolExecutor | ( | size_t | numThreads, |
| std::unique_ptr< BlockingQueue< CPUTask >> | taskQueue, | ||
| std::shared_ptr< ThreadFactory > | threadFactory = std::make_shared<NamedThreadFactory>("CPUThreadPool") |
||
| ) |
Definition at line 31 of file CPUThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::setNumThreads().
| folly::CPUThreadPoolExecutor::CPUThreadPoolExecutor | ( | std::pair< size_t, size_t > | numThreads, |
| std::unique_ptr< BlockingQueue< CPUTask >> | taskQueue, | ||
| std::shared_ptr< ThreadFactory > | threadFactory = std::make_shared<NamedThreadFactory>("CPUThreadPool") |
||
| ) |
Definition at line 43 of file CPUThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::setNumThreads().
|
explicit |
Definition at line 73 of file CPUThreadPoolExecutor.cpp.
| folly::CPUThreadPoolExecutor::CPUThreadPoolExecutor | ( | size_t | numThreads, |
| std::shared_ptr< ThreadFactory > | threadFactory | ||
| ) |
Definition at line 55 of file CPUThreadPoolExecutor.cpp.
| folly::CPUThreadPoolExecutor::CPUThreadPoolExecutor | ( | std::pair< size_t, size_t > | numThreads, |
| std::shared_ptr< ThreadFactory > | threadFactory | ||
| ) |
Definition at line 64 of file CPUThreadPoolExecutor.cpp.
| folly::CPUThreadPoolExecutor::CPUThreadPoolExecutor | ( | size_t | numThreads, |
| int8_t | numPriorities, | ||
| std::shared_ptr< ThreadFactory > | threadFactory = std::make_shared<NamedThreadFactory>("CPUThreadPool") |
||
| ) |
Definition at line 78 of file CPUThreadPoolExecutor.cpp.
| folly::CPUThreadPoolExecutor::CPUThreadPoolExecutor | ( | size_t | numThreads, |
| int8_t | numPriorities, | ||
| size_t | maxQueueSize, | ||
| std::shared_ptr< ThreadFactory > | threadFactory = std::make_shared<NamedThreadFactory>("CPUThreadPool") |
||
| ) |
Definition at line 89 of file CPUThreadPoolExecutor.cpp.
|
override |
Definition at line 101 of file CPUThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::stop(), and threadsToStop_.
|
overridevirtual |
Enqueue a function to executed by this executor. This and all variants must be threadsafe.
Implements folly::ThreadPoolExecutor.
Definition at line 106 of file CPUThreadPoolExecutor.cpp.
References folly::gen::move.
Referenced by addWithPriority(), and TEST().
|
overridevirtual |
Implements folly::ThreadPoolExecutor.
Definition at line 110 of file CPUThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::ensureActiveThreads(), folly::gen::move, and taskQueue_.
| void folly::CPUThreadPoolExecutor::add | ( | Func | func, |
| int8_t | priority, | ||
| std::chrono::milliseconds | expiration, | ||
| Func | expireCallback = nullptr |
||
| ) |
Definition at line 125 of file CPUThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::ensureActiveThreads(), getNumPriorities(), folly::gen::move, and taskQueue_.
Enqueue a function with a given priority, where 0 is the medium priority This is up to the implementation to enforce
Reimplemented from folly::Executor.
Definition at line 121 of file CPUThreadPoolExecutor.cpp.
References add(), and folly::gen::move.
|
overridevirtual |
Reimplemented from folly::Executor.
Definition at line 139 of file CPUThreadPoolExecutor.cpp.
References taskQueue_.
Referenced by add().
|
overrideprivatevirtual |
Implements folly::ThreadPoolExecutor.
Definition at line 218 of file CPUThreadPoolExecutor.cpp.
References taskQueue_.
|
protected |
Definition at line 148 of file CPUThreadPoolExecutor.cpp.
References taskQueue_.
| size_t folly::CPUThreadPoolExecutor::getTaskQueueSize | ( | ) | const |
Definition at line 143 of file CPUThreadPoolExecutor.cpp.
References taskQueue_.
|
overrideprivatevirtual |
Implements folly::ThreadPoolExecutor.
Definition at line 210 of file CPUThreadPoolExecutor.cpp.
References i, folly::Executor::LO_PRI, taskQueue_, and threadsToStop_.
|
private |
Definition at line 162 of file CPUThreadPoolExecutor.cpp.
References tryDecrToStop(), and folly::ThreadPoolExecutor::tryTimeoutThread().
Referenced by threadRun().
|
overrideprivatevirtual |
Implements folly::ThreadPoolExecutor.
Definition at line 174 of file CPUThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::StoppedThreadQueue::add(), folly::ThreadPoolExecutor::isJoin_, folly::gen::move, folly::ThreadPoolExecutor::observers_, folly::ThreadPoolListHook::registerThread(), folly::ThreadPoolExecutor::ThreadList::remove(), folly::ThreadPoolExecutor::runTask(), folly::ThreadPoolExecutor::stoppedThreads_, taskQueue_, taskShouldStop(), folly::ThreadPoolExecutor::threadList_, folly::ThreadPoolExecutor::threadListLock_, folly::ThreadPoolExecutor::threadPoolHook_, threadsToStop_, folly::ThreadPoolExecutor::threadTimeout_, tryDecrToStop(), and UNLIKELY.
|
private |
Definition at line 153 of file CPUThreadPoolExecutor.cpp.
References threadsToStop_.
Referenced by taskShouldStop(), and threadRun().
|
static |
Definition at line 136 of file CPUThreadPoolExecutor.h.
|
private |
Definition at line 149 of file CPUThreadPoolExecutor.h.
Referenced by add(), getNumPriorities(), getPendingTaskCountImpl(), getTaskQueue(), getTaskQueueSize(), stopThreads(), and threadRun().
|
private |
Definition at line 150 of file CPUThreadPoolExecutor.h.
Referenced by stopThreads(), threadRun(), tryDecrToStop(), and ~CPUThreadPoolExecutor().