ThreadWeaver

resourcerestrictionpolicy.h
1/* -*- C++ -*-
2 This file declares the ResourceRestrictionPolicy 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 RESOURCE_RESTRICTION_POLICY_H
12#define RESOURCE_RESTRICTION_POLICY_H
13
14#include <QtGlobal>
15
16#include "jobpointer.h"
17#include "queuepolicy.h"
18
19namespace ThreadWeaver
20{
21class JobInterface;
22
23/** @brief ResourceRestrictionPolicy is used to limit the number of concurrent accesses to the same resource.
24 *
25 * If a set of Jobs accesses a resource that can be overloaded, this may degrade application performance. For
26 * example, loading too many files from the hard disc at the same time may lead to longer load times.
27 * ResourceRestrictionPolicy can be used to cap the number of accesses. Resource restriction policies are
28 * shared between the affected jobs. All jobs that share a resource restriction policy have to acquire
29 * permission from the policy before they can run. In this way, resource restrictions can be compared to
30 * semaphores, only that they require no locking at the thread level.
31 * The example uses a resource restriction to limit the number of images files that are loaded from
32 * the disk at the same time.
33 */
34
35class THREADWEAVER_EXPORT ResourceRestrictionPolicy : public QueuePolicy
36{
37public:
38 explicit ResourceRestrictionPolicy(int cap = 0);
40
41 /** @brief Cap the number of simultaneously executing jobs.
42 * Capping the amount of jobs will make sure that at max the number of jobs executing at any time is
43 * limited to the capped amount. Note that immediately after setting the amount of running jobs may be
44 * higher than the set amount. This setting only limits the starting of new jobs.
45 * @param newCap the new cap to limit the amount of parallel jobs.
46 */
47 void setCap(int newCap);
48 int cap() const;
49 bool canRun(JobPointer) override;
50 void free(JobPointer) override;
51 void release(JobPointer) override;
52 void destructed(JobInterface *job) override;
53
54private:
55 class Private;
56 Private *const d;
57};
58
59}
60
61#endif // RESOURCE_RESTRICTION_POLICY_H
QueuePolicy is an interface for customizations of the queueing behaviour of jobs.
Definition queuepolicy.h:39
ResourceRestrictionPolicy is used to limit the number of concurrent accesses to the same resource.
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.