| 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 | |
| 17 | namespace ThreadWeaver |
| 18 | { |
| 19 | class JobInterface; |
| 20 | |
| 21 | /*! |
| 22 | * \class ThreadWeaver::QueuePolicy |
| 23 | * \inheaderfile ThreadWeaver/QueuePolicy |
| 24 | * \inmodule ThreadWeaver |
| 25 | * |
| 26 | * \brief QueuePolicy is an interface for customizations of the queueing behaviour of jobs. |
| 27 | * |
| 28 | * A job can have a number of queue policies assigned. In that case, the job is only |
| 29 | * executed when the method canRun() of all assigned policies return true. For every call to |
| 30 | * canRun() that returns true, it is guaranteed that the method free() or the method release() |
| 31 | * is called. Calling free() means the job has been executed, while calling release() means |
| 32 | * the job was not executed for external reasons, and will be tried later on. |
| 33 | * |
| 34 | * As an example, dependencies can be implemented using a QueuePolicy: canRun() returns true |
| 35 | * when the job has no unresolved dependencies. free() and release() are empty. |
| 36 | * |
| 37 | * A job can have multiple queue policies assigned, and will only be executed if all of them |
| 38 | * return true from canRun() within the same execution attempt. Jobs only keep a reference to the |
| 39 | * QueuePolicy. Therefore, the same policy object can be assigned to multiple jobs and this way |
| 40 | * control the way all those jobs are executed. Jobs never assume ownership of their assigned queue |
| 41 | * policies. |
| 42 | */ |
| 43 | class THREADWEAVER_EXPORT QueuePolicy |
| 44 | { |
| 45 | public: |
| 46 | /*! |
| 47 | */ |
| 48 | virtual ~QueuePolicy() |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | /*! \brief canRun() is called before the job is executed. |
| 53 | * The job will only be executed if canRun() returns true. |
| 54 | */ |
| 55 | virtual bool canRun(JobPointer) = 0; |
| 56 | |
| 57 | /*! \brief free() is called after the job has been executed. |
| 58 | * It is guaranteed that free is called only after canRun() |
| 59 | * returned true at an earlier time. |
| 60 | */ |
| 61 | virtual void free(JobPointer) = 0; |
| 62 | |
| 63 | /*! \brief release() is called if canRun() returned true, but the job has not been executed for external reasons. |
| 64 | * |
| 65 | * For example, a second QueuePolicy could have returned false from canRun() for the same job. |
| 66 | */ |
| 67 | virtual void release(JobPointer) = 0; |
| 68 | |
| 69 | /*! \brief destructing() is called when a Job that has this queue policy assigned gets destructed. |
| 70 | */ |
| 71 | virtual void destructed(JobInterface *job) = 0; |
| 72 | }; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | #endif |
| 77 | |