ThreadWeaver 5.109.0
job.h
1/* -*- C++ -*-
2 This file declares the Job class.
3
4 SPDX-FileCopyrightText: 2004-2013 Mirko Boehm <mirko@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7
8 $Id: Job.h 32 2005-08-17 08:38:01Z mirko $
9*/
10
11#ifndef THREADWEAVER_JOB_H
12#define THREADWEAVER_JOB_H
13
14#include "jobinterface.h"
15#include "jobpointer.h"
16#include "threadweaver_export.h"
17
18class QMutex;
19class QWaitCondition;
20
21namespace ThreadWeaver
22{
23namespace Private
24{
25class Job_Private;
26}
27
28class Thread;
29class QueuePolicy;
30class QueueAPI;
31class Executor;
32
46class THREADWEAVER_EXPORT Job : public JobInterface
47{
48public:
50 Job();
51 Job(Private::Job_Private *d);
52
54 ~Job() override;
55
65 void execute(const JobPointer &job, Thread *) override;
66
68 void blockingExecute() override;
69
75 Executor *setExecutor(Executor *executor) override;
76
78 Executor *executor() const override;
79
89 int priority() const override;
90
94 void setStatus(Status) override;
95
100 Status status() const override;
101
112 bool success() const override;
113
124 void requestAbort() override
125 {
126 }
127
137 void aboutToBeQueued(QueueAPI *api) override;
138
140 void aboutToBeQueued_locked(QueueAPI *api) override;
141
151 void aboutToBeDequeued(QueueAPI *api) override;
152
154 void aboutToBeDequeued_locked(QueueAPI *api) override;
155
157 bool isFinished() const override;
158
165
168
170 QList<QueuePolicy *> queuePolicies() const override;
171
173 QMutex *mutex() const override;
174
175private:
176 Private::Job_Private *d_;
177
178protected:
179 Private::Job_Private *d();
180 const Private::Job_Private *d() const;
181
182 friend class Executor;
193 virtual void run(JobPointer self, Thread *thread) override = 0;
194
200 void defaultBegin(const JobPointer &job, Thread *thread) override;
201
207 void defaultEnd(const JobPointer &job, Thread *thread) override;
208};
209
210}
211
212#endif // THREADWEAVER_JOB_H
A Job is a simple abstraction of an action that is to be executed in a thread context.
Definition job.h:47
void defaultBegin(const JobPointer &job, Thread *thread) override
Perform standard tasks before starting the execution of a job.
void blockingExecute() override
Perform the job synchronously in the current thread.
Status status() const override
The status of the job.
void aboutToBeDequeued(QueueAPI *api) override
This Job is about the be dequeued from the weaver's job queue.
Executor * setExecutor(Executor *executor) override
Set the Executor object that is supposed to run the job.
void assignQueuePolicy(QueuePolicy *) override
Assign a queue policy.
void removeQueuePolicy(QueuePolicy *) override
Remove a queue policy from this job.
bool isFinished() const override
Returns true if the jobs's execute method finished.
QMutex * mutex() const override
The mutex used to protect this job.
void aboutToBeDequeued_locked(QueueAPI *api) override
Called from aboutToBeDequeued() while the mutex is being held.
void setStatus(Status) override
Set the status of the Job.
Job()
Construct a Job.
int priority() const override
The queueing priority of the job.
void aboutToBeQueued(QueueAPI *api) override
The job is about to be added to the weaver's job queue.
virtual void run(JobPointer self, Thread *thread) override=0
The method that actually performs the job.
~Job() override
Destructor.
void execute(const JobPointer &job, Thread *) override
Perform the job.
bool success() const override
Return whether the Job finished successfully or not.
Executor * executor() const override
Returns the executor currently set on the Job.
void aboutToBeQueued_locked(QueueAPI *api) override
Called from aboutToBeQueued() while the mutex is being held.
QList< QueuePolicy * > queuePolicies() const override
Return the queue policies assigned to this Job.
void requestAbort() override
Abort the execution of the job.
Definition job.h:124
void defaultEnd(const JobPointer &job, Thread *thread) override
Perform standard task after the execution of a job.
QueuePolicy is an interface for customizations of the queueing behaviour of jobs.
Definition queuepolicy.h:39
Thread represents a worker thread in a Queue's inventory.
Definition thread.h:28