class EE::System::ThreadPool¶
Overview¶
#include <threadpool.hpp> class ThreadPool: private EE::NonCopyable, public EE::Executor { public: // structs struct Work; // construction ThreadPool(Uint32 numThreads, bool terminateOnClose = false); virtual ~ThreadPool(); // methods static std::shared_ptr<ThreadPool> createShared(Uint32 numThreads, bool terminateOnClose = false); static std::unique_ptr<ThreadPool> createUnique(Uint32 numThreads, bool terminateOnClose = false); static ThreadPool* createRaw(Uint32 numThreads, bool terminateOnClose = false); Uint64 run(Executor::Function func, const std::function<void(const Uint64&)>& doneCallback = {}, const Uint64& tag = 0); virtual void execute(Executor::Function func); template <typename F> auto submit(F&& fn); Uint32 numThreads() const; bool terminateOnClose() const; void setTerminateOnClose(bool terminateOnClose); bool existsIdInQueue(const Uint64& id); bool existsTagInQueue(const Uint64& tag); bool removeId(const Uint64& id); bool removeWithTag(const Uint64& tag); };
Inherited Members¶
public: // typedefs typedef SmallUniqueFunction<void(), FunctionInlineSize> Function; // fields static constexpr std::size_t FunctionInlineSize = 64; // methods virtual void execute(Function function) = 0;
Detailed Documentation¶
Methods¶
Uint64 run(Executor::Function func, const std::function<void(const Uint64&)>& doneCallback = {}, const Uint64& tag = 0)
Queues func. Work items are move-only, so closures may own move-only state.
virtual void execute(Executor::Function func)
Executor interface: queues the function like run().
template <typename F> auto submit(F&& fn)
Queues fn and returns a task resolved with its return value on the worker thread. If the pool is shutting down the work is dropped and the task becomes abandoned.