DDraceNetwork Docs
CJobPool Class Reference

#include <jobs.h>

Collaboration diagram for CJobPool:
[legend]

Public Member Functions

 CJobPool ()
 
 ~CJobPool ()
 
void Init (int NumThreads) REQUIRES(!m_Lock)
 
void Shutdown () REQUIRES(!m_Lock) REQUIRES(!m_LockRunning)
 
void Add (std::shared_ptr< IJob > pJob) REQUIRES(!m_Lock)
 

Private Member Functions

std::shared_ptr< IJob > m_pFirstJob GUARDED_BY (m_Lock)
 
std::shared_ptr< IJob > m_pLastJob GUARDED_BY (m_Lock)
 
std::deque< std::shared_ptr< IJob > > m_RunningJobs GUARDED_BY (m_LockRunning)
 
void RunLoop () NO_THREAD_SAFETY_ANALYSIS
 

Static Private Member Functions

static void WorkerThread (void *pUser) NO_THREAD_SAFETY_ANALYSIS
 

Private Attributes

std::vector< void * > m_vpThreads
 
std::atomic< bool > m_Shutdown
 
CLock m_Lock
 
SEMAPHORE m_Semaphore
 
CLock m_LockRunning
 

Detailed Description

A job pool which runs jobs in one or more worker threads.

See also
IJob

Constructor & Destructor Documentation

◆ CJobPool()

CJobPool::CJobPool ( )

◆ ~CJobPool()

CJobPool::~CJobPool ( )

Member Function Documentation

◆ Add()

void CJobPool::Add ( std::shared_ptr< IJob pJob)

Adds a job to the queue of the job pool.

Parameters
pJobThe job to enqueue.
Remarks
If the job pool is already shutting down, no additional jobs will be enqueue anymore. Abortable jobs will immediately be aborted.

◆ GUARDED_BY() [1/3]

std::shared_ptr< IJob > m_pFirstJob CJobPool::GUARDED_BY ( m_Lock  )
private

◆ GUARDED_BY() [2/3]

std::shared_ptr< IJob > m_pLastJob CJobPool::GUARDED_BY ( m_Lock  )
private

◆ GUARDED_BY() [3/3]

std::deque< std::shared_ptr< IJob > > m_RunningJobs CJobPool::GUARDED_BY ( m_LockRunning  )
private

◆ Init()

void CJobPool::Init ( int  NumThreads)

Initializes the job pool with the given number of worker threads.

Parameters
NumTheadsThe number of worker threads.
Remarks
Must be called on the main thread.

◆ RunLoop()

void CJobPool::RunLoop ( )
private

◆ Shutdown()

void CJobPool::Shutdown ( )

Shuts down the job pool. Aborts all abortable jobs. Then waits for all worker threads to complete all remaining queued jobs and terminate.

Remarks
Must be called on the main thread.

◆ WorkerThread()

void CJobPool::WorkerThread ( void *  pUser)
staticprivate

Member Data Documentation

◆ m_Lock

CLock CJobPool::m_Lock
private

◆ m_LockRunning

CLock CJobPool::m_LockRunning
private

◆ m_Semaphore

SEMAPHORE CJobPool::m_Semaphore
private

◆ m_Shutdown

std::atomic<bool> CJobPool::m_Shutdown
private

◆ m_vpThreads

std::vector<void *> CJobPool::m_vpThreads
private

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