ZNC
trunk
|
A job is a task which should run without blocking the main thread. More...
#include <Threads.h>
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 |
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.
enum CJob::EJobState |
|
inline |
|
inlinevirtual |
Destructor, always called from the main thread.
|
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.
|
pure virtual |
This function is called in a separate thread and can do heavy, blocking work.
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.
|
friend |