ZNC  trunk
Public Types | Public Member Functions | Friends | List of all members
CJob Class Referenceabstract

A job is a task which should run without blocking the main thread. More...

#include <Threads.h>

+ Inheritance diagram for CJob:

Public Types

enum  EJobState { READY , RUNNING , DONE , CANCELLED }
 

Public Member Functions

 CJob ()
 
virtual ~CJob ()
 Destructor, always called from the main thread. More...
 
virtual void runThread ()=0
 This function is called in a separate thread and can do heavy, blocking work. More...
 
virtual void runMain ()=0
 This function is called from the main thread after runThread() finishes. More...
 
bool wasCancelled () const
 This can be used to check if the job was cancelled. More...
 

Friends

class CThreadPool
 

Detailed Description

A job is a task which should run without blocking the main thread.

You do this by inheriting from this class and implementing the pure virtual methods runThread(), which gets executed in a separate thread and does not block the main thread, and runMain() which gets automatically called from the main thread after runThread() finishes.

After you create a new instance of your class, you can pass it to CThreadPool()::Get().addJob(job) to start it. The thread pool automatically deletes your class after it finished.

For modules you should use CModuleJob instead.

Member Enumeration Documentation

◆ EJobState

Enumerator
READY 
RUNNING 
DONE 
CANCELLED 

Constructor & Destructor Documentation

◆ CJob()

CJob::CJob ( )
inline

◆ ~CJob()

virtual CJob::~CJob ( )
inlinevirtual

Destructor, always called from the main thread.

Member Function Documentation

◆ runMain()

virtual void CJob::runMain ( )
pure virtual

This function is called from the main thread after runThread() finishes.

It can be used to handle the results from runThread() without needing synchronization primitives.

◆ runThread()

virtual void CJob::runThread ( )
pure virtual

This function is called in a separate thread and can do heavy, blocking work.

◆ wasCancelled()

bool CJob::wasCancelled ( ) const

This can be used to check if the job was cancelled.

For example, runThread() can return early if this returns true.

Friends And Related Function Documentation

◆ CThreadPool

friend class CThreadPool
friend

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