DDraceNetwork Docs
IJob Class Referenceabstract

#include <jobs.h>

Inheritance diagram for IJob:
[legend]

Public Types

enum  EJobState { STATE_QUEUED = 0 , STATE_RUNNING , STATE_DONE , STATE_ABORTED }
 

Public Member Functions

 IJob ()
 
virtual ~IJob ()
 
 IJob (const IJob &Other)=delete
 
IJoboperator= (const IJob &Other)=delete
 
EJobState State () const
 
bool Done () const
 
virtual bool Abort ()
 
bool IsAbortable () const
 

Protected Member Functions

virtual void Run ()=0
 
void Abortable (bool Abortable)
 

Private Attributes

std::shared_ptr< IJobm_pNext
 
std::atomic< EJobStatem_State
 
std::atomic< bool > m_Abortable
 

Friends

class CJobPool
 

Detailed Description

A job which runs in a worker thread of a job pool.

See also
CJobPool

Member Enumeration Documentation

◆ EJobState

The state of a job in the job pool.

Enumerator
STATE_QUEUED 

Job has been created/queued but not started on a worker thread yet.

STATE_RUNNING 

Job is currently running on a worker thread.

STATE_DONE 

Job was completed successfully.

STATE_ABORTED 

Job was aborted. Note the job may or may not still be running while in this state.

See also
IsAbortable

Constructor & Destructor Documentation

◆ IJob() [1/2]

IJob::IJob ( )

◆ ~IJob()

IJob::~IJob ( )
virtualdefault

◆ IJob() [2/2]

IJob::IJob ( const IJob Other)
delete

Member Function Documentation

◆ Abort()

bool IJob::Abort ( )
virtual

Aborts the job, if it can be aborted.

Returns
true if abort was accepted, false otherwise.
Remarks
May be overridden to delegate abort to other jobs. Note that this function may be called from any thread and should be thread-safe.

Reimplemented in CChooseMaster::CJob, and CSkins::CSkinDownloadJob.

◆ Abortable()

void IJob::Abortable ( bool  Abortable)
protected

Sets whether this job can be aborted.

Remarks
Has no effect if the job has already been aborted.
See also
IsAbortable

◆ Done()

bool IJob::Done ( ) const

Returns whether the job was completed, i.e. whether it's not still queued or running.

Returns
true if the job is done, false otherwise.

◆ IsAbortable()

bool IJob::IsAbortable ( ) const

Returns whether the job can be aborted. Jobs that are abortable may have their state set to STATE_ABORTED at any point if the job was aborted. The job state should be checked periodically in the Run function and the job should terminate at the earliest, safe opportunity when aborted. Scheduled jobs which are not abortable are guaranteed to fully complete before the job pool is shut down.

Returns
true if the job can be aborted, false otherwise.

◆ operator=()

IJob & IJob::operator= ( const IJob Other)
delete

◆ Run()

virtual void IJob::Run ( )
protectedpure virtual

◆ State()

IJob::EJobState IJob::State ( ) const

Returns the state of the job.

Remarks
Accessing jobs in any other way that with the base functions of IJob is generally not thread-safe unless the job is in STATE_DONE or has not been enqueued yet.
Returns
State of the job.

Friends And Related Function Documentation

◆ CJobPool

friend class CJobPool
friend

Member Data Documentation

◆ m_Abortable

std::atomic<bool> IJob::m_Abortable
private

◆ m_pNext

std::shared_ptr<IJob> IJob::m_pNext
private

◆ m_State

std::atomic<EJobState> IJob::m_State
private

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