RADLib
RADical C++ application framework
RADCore::RADThreadPool Class Reference

Simple worker thread pool that reports completion through RADFuture. More...

#include <RADCore.h>

+ Inheritance diagram for RADCore::RADThreadPool:
+ Collaboration diagram for RADCore::RADThreadPool:

Public Member Functions

 RADThreadPool (size_t threadCount=std::thread::hardware_concurrency())
 Creates a pool with threadCount workers. More...
 
 ~RADThreadPool () override
 Stops workers after queued tasks complete. More...
 
RADFuture submit (EventLoop &completionLoop, std::function< RADVariant()> task)
 Submits task and posts completion wakeup to completionLoop. More...
 
template<typename F >
auto submitTyped (EventLoop &completionLoop, F &&task) -> RADFutureT< std::invoke_result_t< F >>
 Submits a typed task and posts completion wakeup to completionLoop. More...
 
template<typename F >
auto submitCancellable (EventLoop &completionLoop, RADCancellationToken token, F &&task) -> RADFutureT< std::invoke_result_t< F, RADCancellationToken >>
 Submits a typed task that receives a cancellation token. More...
 
void waitForDone ()
 Blocks until queued and active tasks are complete. More...
 
size_t threadCount () const
 Returns number of worker threads. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Detailed Description

Simple worker thread pool that reports completion through RADFuture.

Constructor & Destructor Documentation

◆ RADThreadPool()

RADCore::RADThreadPool::RADThreadPool ( size_t  threadCount = std::thread::hardware_concurrency())
explicit

Creates a pool with threadCount workers.

◆ ~RADThreadPool()

RADCore::RADThreadPool::~RADThreadPool ( )
override

Stops workers after queued tasks complete.

Member Function Documentation

◆ submit()

RADFuture RADCore::RADThreadPool::submit ( EventLoop completionLoop,
std::function< RADVariant()>  task 
)

Submits task and posts completion wakeup to completionLoop.

◆ submitCancellable()

template<typename F >
auto RADCore::RADThreadPool::submitCancellable ( EventLoop completionLoop,
RADCancellationToken  token,
F &&  task 
) -> RADFutureT<std::invoke_result_t<F, RADCancellationToken>>
inline

Submits a typed task that receives a cancellation token.

◆ submitTyped()

template<typename F >
auto RADCore::RADThreadPool::submitTyped ( EventLoop completionLoop,
F &&  task 
) -> RADFutureT<std::invoke_result_t<F>>
inline

Submits a typed task and posts completion wakeup to completionLoop.

◆ threadCount()

size_t RADCore::RADThreadPool::threadCount ( ) const

Returns number of worker threads.

◆ waitForDone()

void RADCore::RADThreadPool::waitForDone ( )

Blocks until queued and active tasks are complete.


The documentation for this class was generated from the following file: