ThreadWeaver

queuepolicy.h
1 /* -*- C++ -*-
2  This file declares the QueuePolicy class.
3 
4  SPDX-FileCopyrightText: 2004, 2005, 2006 Mirko Boehm <[email protected]>
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 
17 namespace ThreadWeaver
18 {
19 class 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  */
38 class THREADWEAVER_EXPORT QueuePolicy
39 {
40 public:
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
virtual void release(quint64 objid)
QueuePolicy is an interface for customizations of the queueing behaviour of jobs.
Definition: queuepolicy.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Sep 29 2023 04:02:13 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.