|
#include <ThreadPool.h>
Public Member Functions | |
| ThreadPool (uint32_t threadLimit, std::chrono::milliseconds threadIdleSeconds, const String &threadName, LogEngine *logEngine) | |
| virtual void | execute (const SRunable &task) |
| void | threadEvent (Thread *thread, ThreadEvent::Type eventType, SRunable runable) override |
| virtual void | stop () |
| size_t | size () const |
Public Member Functions inherited from sptk::ThreadEvent | |
| virtual void | threadEvent (Thread *thread, Type eventType, SRunable runable)=0 |
| Thread event callback function. More... | |
| virtual | ~ThreadEvent ()=default |
| Destructor. | |
Additional Inherited Members | |
Public Types inherited from sptk::ThreadEvent | |
| enum class | Type : uint8_t { THREAD_STARTED , THREAD_FINISHED , RUNABLE_STARTED , RUNABLE_FINISHED , IDLE_TIMEOUT } |
| Thread event type. More... | |
Controls creation and execution of the threads.
When a thread is requested from the thread pool, it ether creates a new thread or returns one from the thread pool. If a thread is idle for the period longer than defined in constructor, it's automatically terminated.
| sptk::ThreadPool::ThreadPool | ( | uint32_t | threadLimit, |
| std::chrono::milliseconds | threadIdleSeconds, | ||
| const String & | threadName, | ||
| LogEngine * | logEngine | ||
| ) |
Constructor
| threadLimit | Maximum number of threads in this pool |
| threadIdleSeconds | Maximum period of inactivity (seconds) for thread in the pool before thread is terminated |
| threadName | Thread pool own threadName |
|
virtual |
Executes task
| task | Task to execute |
| size_t sptk::ThreadPool::size | ( | ) | const |
Number of active threads in the pool
|
virtual |
Sends terminate() message to all worker threads, and sets shutdown state
After thread pool is stopped, it no longer accepts tasks for execution.
Reimplemented in sptk::TCPServer.
|
overridevirtual |
Thread event callback function
Receives events that occur in the threads
| thread | Thread where event occured |
| eventType | Thread event type |
| runable | Related runable (if any) |
Implements sptk::ThreadEvent.