ThreadWeaver

queuepolicy.h
1/* -*- C++ -*-
2 This file declares the QueuePolicy class.
3
4 SPDX-FileCopyrightText: 2004, 2005, 2006 Mirko Boehm <mirko@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7
8 $Id: DebuggingAids.h 30 2005-08-16 16:16:04Z mirko $
9*/
10
11#ifndef QUEUEPOLICY_H
12#define QUEUEPOLICY_H
13
14#include "jobpointer.h"
15#include "threadweaver_export.h"
16
17namespace ThreadWeaver
18{
19class JobInterface;
20
21/** @brief QueuePolicy is an interface for customizations of the queueing behaviour of jobs.
22 *
23 * A job can have a number of queue policies assigned. In that case, the job is only
24 * executed when the method canRun() of all assigned policies return true. For every call to
25 * canRun() that returns true, it is guaranteed that the method free() or the method release()
26 * is called. Calling free() means the job has been executed, while calling release() means
27 * the job was not executed for external reasons, and will be tried later on.
28 *
29 * As an example, dependencies can be implemented using a QueuePolicy: canRun() returns true
30 * when the job has no unresolved dependencies. free() and release() are empty.
31 *
32 * A job can have multiple queue policies assigned, and will only be executed if all of them
33 * return true from canRun() within the same execution attempt. Jobs only keep a reference to the
34 * QueuePolicy. Therefore, the same policy object can be assigned to multiple jobs and this way
35 * control the way all those jobs are executed. Jobs never assume ownership of their assigned queue
36 * policies.
37 */
38class THREADWEAVER_EXPORT QueuePolicy
39{
40public:
41 virtual ~QueuePolicy()
42 {
43 }
44
45 /** @brief canRun() is called before the job is executed.
46 * The job will only be executed if canRun() returns true.
47 */
48 virtual bool canRun(JobPointer) = 0;
49
50 /** @brief free() is called after the job has been executed.
51 * It is guaranteed that free is called only after canRun()
52 * returned true at an earlier time.
53 */
54 virtual void free(JobPointer) = 0;
55
56 /** @brief release() is called if canRun() returned true, but the job has not been executed for external reasons.
57 *
58 * For example, a second QueuePolicy could have returned false from canRun() for the same job.
59 */
60 virtual void release(JobPointer) = 0;
61
62 /** @brief destructing() is called when a Job that has this queue policy assigned gets destructed.
63 */
64 virtual void destructed(JobInterface *job) = 0;
65};
66
67}
68
69#endif
QueuePolicy is an interface for customizations of the queueing behaviour of jobs.
Definition queuepolicy.h:39
virtual void destructed(JobInterface *job)=0
destructing() is called when a Job that has this queue policy assigned gets destructed.
virtual void free(JobPointer)=0
free() is called after the job has been executed.
virtual void release(JobPointer)=0
release() is called if canRun() returned true, but the job has not been executed for external reasons...
virtual bool canRun(JobPointer)=0
canRun() is called before the job is executed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:58:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.