hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
CodegenTaskDispatcher Class Reference

#include <codegenTaskDispatcher.hpp>

Public Member Functions

 CodegenTaskDispatcher (size_t threadCount=0)
 
 ~CodegenTaskDispatcher ()
 
 CodegenTaskDispatcher (const CodegenTaskDispatcher &)=delete
 
CodegenTaskDispatcheroperator= (const CodegenTaskDispatcher &)=delete
 
void dispatch (std::function< void()> task)
 Dispatch a task to the thread pool.
 
void wait ()
 Wait for all dispatched tasks to complete.
 

Private Member Functions

void workerLoop ()
 

Private Attributes

std::vector< std::thread > workers
 
std::queue< std::function< void()> > taskQueue
 
std::mutex queueMutex
 
std::condition_variable queueCondition
 
std::mutex waitMutex
 
std::condition_variable waitCondition
 
std::atomic< size_t > activeTasks {0}
 
std::atomic< bool > stop {false}
 

Detailed Description

Definition at line 18 of file codegenTaskDispatcher.hpp.

Constructor & Destructor Documentation

◆ CodegenTaskDispatcher() [1/2]

CodegenTaskDispatcher ( size_t  threadCount = 0)
explicit

Definition at line 9 of file codegenTaskDispatcher.cpp.

References CodegenTaskDispatcher::workerLoop(), and CodegenTaskDispatcher::workers.

Here is the call graph for this function:

◆ ~CodegenTaskDispatcher()

◆ CodegenTaskDispatcher() [2/2]

Member Function Documentation

◆ dispatch()

void dispatch ( std::function< void()>  task)

Dispatch a task to the thread pool.

Parameters
taskThe task to execute.

Definition at line 32 of file codegenTaskDispatcher.cpp.

References CodegenTaskDispatcher::activeTasks, CodegenTaskDispatcher::queueCondition, CodegenTaskDispatcher::queueMutex, and CodegenTaskDispatcher::taskQueue.

Referenced by LLVMCodegen::generate().

Here is the caller graph for this function:

◆ operator=()

CodegenTaskDispatcher & operator= ( const CodegenTaskDispatcher )
delete

◆ wait()

void wait ( )

Wait for all dispatched tasks to complete.

Definition at line 41 of file codegenTaskDispatcher.cpp.

References CodegenTaskDispatcher::activeTasks, CodegenTaskDispatcher::waitCondition, and CodegenTaskDispatcher::waitMutex.

Referenced by LLVMCodegen::generate().

Here is the caller graph for this function:

◆ workerLoop()

Member Data Documentation

◆ activeTasks

std::atomic<size_t> activeTasks {0}
private

◆ queueCondition

std::condition_variable queueCondition
private

◆ queueMutex

◆ stop

std::atomic<bool> stop {false}
private

◆ taskQueue

std::queue<std::function<void()> > taskQueue
private

◆ waitCondition

std::condition_variable waitCondition
private

◆ waitMutex

std::mutex waitMutex
private

◆ workers

std::vector<std::thread> workers
private

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