|
proxygen
|
#include <ThreadPoolExecutor.h>
Classes | |
| class | Observer |
| struct | PoolStats |
| class | StoppedThreadQueue |
| struct | Task |
| struct | TaskStats |
| struct | TaskStatsCallbackRegistry |
| struct | Thread |
| class | ThreadHandle |
| class | ThreadList |
Public Types | |
| using | TaskStatsCallback = std::function< void(TaskStats)> |
Public Member Functions | |
| ThreadPoolExecutor (size_t maxThreads, size_t minThreads, std::shared_ptr< ThreadFactory > threadFactory, bool isWaitForAll=false) | |
| ~ThreadPoolExecutor () override | |
| void | add (Func func) override=0 |
| virtual void | add (Func func, std::chrono::milliseconds expiration, Func expireCallback)=0 |
| 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 () |
| virtual void | addWithPriority (Func, int8_t priority) |
| virtual uint8_t | getNumPriorities () const |
Static Public Member Functions | |
| 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 | |
| typedef std::shared_ptr< Thread > | ThreadPtr |
Protected Member Functions | |
| void | addThreads (size_t n) |
| void | removeThreads (size_t n, bool isJoin) |
| virtual void | threadRun (ThreadPtr thread)=0 |
| virtual void | stopThreads (size_t n)=0 |
| void | joinStoppedThreads (size_t n) |
| virtual ThreadPtr | makeThread () |
| virtual size_t | getPendingTaskCountImpl ()=0 |
| void | ensureActiveThreads () |
| void | ensureJoined () |
| bool | minActive () |
| bool | tryTimeoutThread () |
| void | joinKeepAliveOnce () |
Protected Member Functions inherited from folly::DefaultKeepAliveExecutor | |
| void | joinKeepAlive () |
Static Protected Member Functions | |
| 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 | |
| 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} |
Additional Inherited Members | |
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 |
Definition at line 55 of file ThreadPoolExecutor.h.
| using folly::ThreadPoolExecutor::TaskStatsCallback = std::function<void(TaskStats)> |
Definition at line 123 of file ThreadPoolExecutor.h.
|
protected |
Definition at line 189 of file ThreadPoolExecutor.h.
|
explicit |
Definition at line 37 of file ThreadPoolExecutor.cpp.
References folly::getSyncVecThreadPoolExecutors().
|
override |
Definition at line 51 of file ThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::ThreadList::get(), folly::getSyncVecThreadPoolExecutors(), joinKeepAliveOnce(), and threadList_.
|
overridepure virtual |
Enqueue a function to executed by this executor. This and all variants must be threadsafe.
Implements folly::Executor.
Implemented in folly::CPUThreadPoolExecutor, and folly::IOThreadPoolExecutor.
|
pure virtual |
Implemented in folly::CPUThreadPoolExecutor, and folly::IOThreadPoolExecutor.
| void folly::ThreadPoolExecutor::addObserver | ( | std::shared_ptr< Observer > | o | ) |
Definition at line 349 of file ThreadPoolExecutor.cpp.
References activeThreads_, ensureActiveThreads(), folly::ThreadPoolExecutor::ThreadList::get(), maxThreads_, observers_, threadList_, and threadListLock_.
Referenced by TEST(), and folly::ThreadPoolExecutor::Observer::threadNotYetStopped().
|
protected |
Definition at line 180 of file ThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::ThreadList::add(), folly::netops::bind(), i, makeThread(), observers_, threadFactory_, threadList_, and threadRun().
Referenced by ensureActiveThreads(), setNumThreads(), and setThreadDeathTimeout().
|
protected |
Definition at line 434 of file ThreadPoolExecutor.cpp.
References activeThreads_, addThreads(), folly::asymmetricLightBarrier(), ensureJoined(), maxThreads_, and threadListLock_.
Referenced by folly::IOThreadPoolExecutor::add(), folly::CPUThreadPoolExecutor::add(), addObserver(), and folly::IOThreadPoolExecutor::getEventBase().
|
protected |
Definition at line 380 of file ThreadPoolExecutor.cpp.
References joinStoppedThreads(), threadListLock_, and threadsToJoin_.
Referenced by ensureActiveThreads().
| std::string folly::ThreadPoolExecutor::getName | ( | ) |
Definition at line 287 of file ThreadPoolExecutor.cpp.
References folly::demangle(), folly::ThreadPoolExecutor::Thread::nextId, threadFactory_, and folly::toStdString().
| size_t folly::ThreadPoolExecutor::getPendingTaskCount | ( | ) |
Definition at line 282 of file ThreadPoolExecutor.cpp.
References getPendingTaskCountImpl(), and threadListLock_.
|
protectedpure virtual |
Implemented in folly::CPUThreadPoolExecutor, and folly::IOThreadPoolExecutor.
Referenced by getPendingTaskCount(), getPoolStats(), makeThread(), setNumThreads(), and tryTimeoutThread().
| ThreadPoolExecutor::PoolStats folly::ThreadPoolExecutor::getPoolStats | ( | ) |
Definition at line 257 of file ThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::PoolStats::activeThreadCount, activeThreads_, folly::ThreadPoolExecutor::ThreadList::get(), getPendingTaskCountImpl(), folly::ThreadPoolExecutor::PoolStats::idleThreadCount, max, folly::ThreadPoolExecutor::PoolStats::maxIdleTime, maxThreads_, now(), folly::ThreadPoolExecutor::PoolStats::pendingTaskCount, folly::ThreadPoolExecutor::PoolStats::threadCount, threadList_, threadListLock_, and folly::ThreadPoolExecutor::PoolStats::totalTaskCount.
Referenced by TEST().
|
inline |
Definition at line 74 of file ThreadPoolExecutor.h.
References f, join(), numActiveThreads(), numThreads(), setNumThreads(), stop(), threadFactory_, and withAll().
| void folly::ThreadPoolExecutor::join | ( | ) |
Definition at line 232 of file ThreadPoolExecutor.cpp.
References activeThreads_, folly::ThreadPoolExecutor::ThreadList::get(), joinKeepAliveOnce(), joinStoppedThreads(), maxThreads_, removeThreads(), folly::ThreadPoolExecutor::StoppedThreadQueue::size(), stoppedThreads_, threadList_, threadListLock_, and threadsToJoin_.
Referenced by getThreadFactory(), and TEST().
|
inlineprotected |
Definition at line 318 of file ThreadPoolExecutor.h.
References folly::exchange(), folly::DefaultKeepAliveExecutor::joinKeepAlive(), and keepAliveJoined_.
Referenced by join(), stop(), and ~ThreadPoolExecutor().
|
protected |
Definition at line 208 of file ThreadPoolExecutor.cpp.
References i, stoppedThreads_, and folly::ThreadPoolExecutor::StoppedThreadQueue::take().
Referenced by ensureJoined(), join(), setNumThreads(), and stop().
|
inlineprotectedvirtual |
Reimplemented in folly::IOThreadPoolExecutor.
Definition at line 222 of file ThreadPoolExecutor.h.
References getPendingTaskCountImpl().
Referenced by addThreads().
|
protected |
Definition at line 462 of file ThreadPoolExecutor.cpp.
References activeThreads_, and minThreads_.
Referenced by tryTimeoutThread().
| size_t folly::ThreadPoolExecutor::numActiveThreads | ( | ) |
Definition at line 120 of file ThreadPoolExecutor.cpp.
References activeThreads_.
Referenced by getThreadFactory().
| size_t folly::ThreadPoolExecutor::numThreads | ( | ) |
Definition at line 116 of file ThreadPoolExecutor.cpp.
References maxThreads_.
Referenced by getThreadFactory(), setNumThreads(), and setThreadFactory().
| void folly::ThreadPoolExecutor::removeObserver | ( | std::shared_ptr< Observer > | o | ) |
Definition at line 363 of file ThreadPoolExecutor.cpp.
References folly::ThreadPoolExecutor::ThreadList::get(), observers_, threadList_, and threadListLock_.
Referenced by TEST(), and folly::ThreadPoolExecutor::Observer::threadNotYetStopped().
|
protected |
Definition at line 203 of file ThreadPoolExecutor.cpp.
References isJoin_, and stopThreads().
Referenced by join(), setNumThreads(), setThreadDeathTimeout(), and stop().
Definition at line 71 of file ThreadPoolExecutor.cpp.
References name, now(), and SCOPE_EXIT.
Referenced by folly::IOThreadPoolExecutor::add(), and folly::CPUThreadPoolExecutor::threadRun().
| void folly::ThreadPoolExecutor::setNumThreads | ( | size_t | numThreads | ) |
Definition at line 125 of file ThreadPoolExecutor.cpp.
References activeThreads_, addThreads(), getPendingTaskCountImpl(), joinStoppedThreads(), maxThreads_, min, minThreads_, numThreads(), observers_, removeThreads(), and threadListLock_.
Referenced by folly::CPUThreadPoolExecutor::CPUThreadPoolExecutor(), getThreadFactory(), folly::IOThreadPoolExecutor::IOThreadPoolExecutor(), and TEST().
|
inline |
Definition at line 157 of file ThreadPoolExecutor.h.
References addThreads(), removeThreads(), and threadTimeout_.
Referenced by TEST().
|
inline |
Definition at line 69 of file ThreadPoolExecutor.h.
References folly::gen::move, numThreads(), and threadFactory_.
| void folly::ThreadPoolExecutor::stop | ( | ) |
Definition at line 215 of file ThreadPoolExecutor.cpp.
References activeThreads_, folly::ThreadPoolExecutor::ThreadList::get(), joinKeepAliveOnce(), joinStoppedThreads(), maxThreads_, removeThreads(), folly::ThreadPoolExecutor::StoppedThreadQueue::size(), stoppedThreads_, threadList_, threadListLock_, and threadsToJoin_.
Referenced by getThreadFactory(), stop< IOThreadPoolExecutor >(), folly::CPUThreadPoolExecutor::~CPUThreadPoolExecutor(), and folly::IOThreadPoolExecutor::~IOThreadPoolExecutor().
|
protectedpure virtual |
Implemented in folly::CPUThreadPoolExecutor, and folly::IOThreadPoolExecutor.
Referenced by removeThreads().
| void folly::ThreadPoolExecutor::subscribeToTaskStats | ( | TaskStatsCallback | cb | ) |
Definition at line 298 of file ThreadPoolExecutor.cpp.
References folly::gen::move, and taskStatsCallbacks_.
|
protectedpure virtual |
Implemented in folly::CPUThreadPoolExecutor, and folly::IOThreadPoolExecutor.
Referenced by addThreads().
|
protected |
Definition at line 393 of file ThreadPoolExecutor.cpp.
References activeThreads_, folly::asymmetricHeavyBarrier(), getPendingTaskCountImpl(), minActive(), and threadsToJoin_.
Referenced by folly::CPUThreadPoolExecutor::taskShouldStop().
|
static |
Execute f against all ThreadPoolExecutors, primarily for retrieving and exporting stats.
Definition at line 249 of file ThreadPoolExecutor.cpp.
References f, and folly::getSyncVecThreadPoolExecutors().
Referenced by getNumThreadPoolExecutors(), and getThreadFactory().
|
protected |
Definition at line 313 of file ThreadPoolExecutor.h.
Referenced by addObserver(), ensureActiveThreads(), getPoolStats(), join(), minActive(), numActiveThreads(), setNumThreads(), stop(), and tryTimeoutThread().
|
protected |
Definition at line 293 of file ThreadPoolExecutor.h.
Referenced by removeThreads(), folly::IOThreadPoolExecutor::threadRun(), and folly::CPUThreadPoolExecutor::threadRun().
|
protected |
Definition at line 288 of file ThreadPoolExecutor.h.
Referenced by folly::IOThreadPoolExecutor::threadRun().
|
protected |
Definition at line 324 of file ThreadPoolExecutor.h.
Referenced by joinKeepAliveOnce().
|
protected |
Definition at line 311 of file ThreadPoolExecutor.h.
Referenced by addObserver(), ensureActiveThreads(), getPoolStats(), join(), numThreads(), setNumThreads(), and stop().
|
protected |
Definition at line 312 of file ThreadPoolExecutor.h.
Referenced by minActive(), and setNumThreads().
|
protected |
Definition at line 300 of file ThreadPoolExecutor.h.
Referenced by addObserver(), addThreads(), removeObserver(), setNumThreads(), folly::IOThreadPoolExecutor::stopThreads(), and folly::CPUThreadPoolExecutor::threadRun().
|
protected |
Definition at line 292 of file ThreadPoolExecutor.h.
Referenced by join(), joinStoppedThreads(), stop(), folly::IOThreadPoolExecutor::stopThreads(), and folly::CPUThreadPoolExecutor::threadRun().
|
protected |
Definition at line 299 of file ThreadPoolExecutor.h.
Referenced by subscribeToTaskStats().
|
protected |
Definition at line 287 of file ThreadPoolExecutor.h.
Referenced by addThreads(), getName(), getThreadFactory(), and setThreadFactory().
|
protected |
Definition at line 290 of file ThreadPoolExecutor.h.
Referenced by folly::IOThreadPoolExecutor::add(), addObserver(), addThreads(), folly::IOThreadPoolExecutor::getPendingTaskCountImpl(), getPoolStats(), join(), folly::IOThreadPoolExecutor::pickThread(), removeObserver(), stop(), folly::IOThreadPoolExecutor::stopThreads(), folly::CPUThreadPoolExecutor::threadRun(), and ~ThreadPoolExecutor().
|
protected |
Definition at line 291 of file ThreadPoolExecutor.h.
Referenced by folly::IOThreadPoolExecutor::add(), addObserver(), ensureActiveThreads(), ensureJoined(), folly::IOThreadPoolExecutor::getEventBase(), getPendingTaskCount(), getPoolStats(), join(), removeObserver(), setNumThreads(), stop(), and folly::CPUThreadPoolExecutor::threadRun().
|
protected |
Definition at line 301 of file ThreadPoolExecutor.h.
Referenced by folly::IOThreadPoolExecutor::threadRun(), and folly::CPUThreadPoolExecutor::threadRun().
|
protected |
Definition at line 315 of file ThreadPoolExecutor.h.
Referenced by ensureJoined(), join(), stop(), and tryTimeoutThread().
|
protected |
Definition at line 316 of file ThreadPoolExecutor.h.
Referenced by setThreadDeathTimeout(), and folly::CPUThreadPoolExecutor::threadRun().