20 #include <znc/zncconfig.h>
33 #include <condition_variable>
128 void jobDone(
CJob* pJob);
132 bool threadNeeded()
const;
134 CJob* getJobFromPipe()
const;
135 void finishJob(
CJob*)
const;
155 size_t m_num_threads;
164 std::list<CJob*> m_jobs;
std::unique_lock< std::mutex > CMutexLocker
A mutex locker should always be used as an automatic variable.
Definition: Threads.h:46
std::condition_variable_any CConditionVariable
A condition variable makes it possible for threads to wait until some condition is reached at which p...
Definition: Threads.h:52
std::mutex CMutex
This class represents a non-recursive mutex.
Definition: Threads.h:39
A job is a task which should run without blocking the main thread.
Definition: Threads.h:67
virtual void runThread()=0
This function is called in a separate thread and can do heavy, blocking work.
virtual ~CJob()
Destructor, always called from the main thread.
Definition: Threads.h:76
bool wasCancelled() const
This can be used to check if the job was cancelled.
EJobState
Definition: Threads.h:71
@ RUNNING
Definition: Threads.h:71
@ DONE
Definition: Threads.h:71
@ CANCELLED
Definition: Threads.h:71
@ READY
Definition: Threads.h:71
virtual void runMain()=0
This function is called from the main thread after runThread() finishes.
friend class CThreadPool
Definition: Threads.h:69
CJob()
Definition: Threads.h:73
Definition: Threads.h:100
int getReadFD() const
Definition: Threads.h:123
void addJob(CJob *job)
Add a job to the thread pool and run it. The job will be deleted when done.
void handlePipeReadable() const
static CThreadPool & Get()
void cancelJobs(const std::set< CJob * > &jobs)
Cancel some jobs that were previously passed to addJob().
void cancelJob(CJob *job)
Cancel a job that was previously passed to addJob().