3 #ifndef INCLUDE_NN_NLIB_THREADING_THREADPOOL_H_
4 #define INCLUDE_NN_NLIB_THREADING_THREADPOOL_H_
25 class ThPoolTask : public ThPoolTaskBase {
31 virtual void operator()() NLIB_NOEXCEPT
NLIB_OVERRIDE { m_Task(); }
34 PackagedTask<R()> m_Task;
45 return this->Init(numThreads, settings);
51 template <class R, class FUNC>
53 size_t Count() NLIB_NOEXCEPT {
return m_ThreadList.size(); }
67 template <
class R,
class FUNC>
81 bool result = m_WorkQueue.push_back_swap(&pTask);
89 return result ? 0 : ENOMEM;
98 #endif // INCLUDE_NN_NLIB_THREADING_THREADPOOL_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
ThreadPool() noexcept
Instantiates the object with default parameters (default constructor). Must be initialized with Init...
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
A container-like class similar to std::queue that can store objects that do not have copy constructor...
UniquePtr owns the pointer, and when it goes out of scope, the pointer is released by the destructor ...
Defines that class that is corresponding to std::unique_ptr.
The class to wrap nlib_thread_attr. nlib_thread_attr_init() and nlib_thread_attr_destroy() are run au...
errno_t GetFuture(Future< R > *p) noexcept
Sets Future to get the result of execution.
errno_t Init() noexcept
Starts a thread and initializes the thread pool.
Class that gets the output of a different thread executing in a thread safe manner. This class is similar to the std::shared_future class of C++11.
errno_t Init(size_t numThreads) noexcept
Starts a thread and initializes the thread pool.
size_t GetHardwareConcurrency() noexcept
Returns the number of hardware threads.
Class that wraps a function to run in a different thread, and gets the return value in a thread safe ...
Implements the Future pattern for multithread programming.
Tasks may be deployed to a pool of threads that have been already created.
errno_t Init(FUNC &func)
Performs initialization.