ThreadWeaver::ResourceRestrictionPolicy

Search for usage in LXR

ThreadWeaver::ResourceRestrictionPolicy Class Reference

#include <resourcerestrictionpolicy.h>

Inheritance diagram for ThreadWeaver::ResourceRestrictionPolicy:

Public Member Functions

 ResourceRestrictionPolicy (int cap=0)
 
bool canRun (JobPointer) override
 
int cap () const
 
void destructed (JobInterface *job) override
 
void free (JobPointer) override
 
void release (JobPointer) override
 
void setCap (int newCap)
 
- Public Member Functions inherited from ThreadWeaver::QueuePolicy

Detailed Description

ResourceRestrictionPolicy is used to limit the number of concurrent accesses to the same resource.

If a set of Jobs accesses a resource that can be overloaded, this may degrade application performance. For example, loading too many files from the hard disc at the same time may lead to longer load times. ResourceRestrictionPolicy can be used to cap the number of accesses. Resource restriction policies are shared between the affected jobs. All jobs that share a resource restriction policy have to acquire permission from the policy before they can run. In this way, resource restrictions can be compared to semaphores, only that they require no locking at the thread level. The example uses a resource restriction to limit the number of images files that are loaded from the disk at the same time.

Definition at line 35 of file resourcerestrictionpolicy.h.

Constructor & Destructor Documentation

◆ ResourceRestrictionPolicy()

ResourceRestrictionPolicy::ResourceRestrictionPolicy ( int cap = 0)
explicit

Definition at line 38 of file resourcerestrictionpolicy.cpp.

◆ ~ResourceRestrictionPolicy()

ResourceRestrictionPolicy::~ResourceRestrictionPolicy ( )
override

Definition at line 44 of file resourcerestrictionpolicy.cpp.

Member Function Documentation

◆ canRun()

bool ResourceRestrictionPolicy::canRun ( JobPointer )
overridevirtual

canRun() is called before the job is executed.

The job will only be executed if canRun() returns true.

Implements ThreadWeaver::QueuePolicy.

Definition at line 61 of file resourcerestrictionpolicy.cpp.

◆ cap()

int ResourceRestrictionPolicy::cap ( ) const

Definition at line 55 of file resourcerestrictionpolicy.cpp.

◆ destructed()

void ResourceRestrictionPolicy::destructed ( JobInterface * job)
overridevirtual

destructing() is called when a Job that has this queue policy assigned gets destructed.

Implements ThreadWeaver::QueuePolicy.

Definition at line 89 of file resourcerestrictionpolicy.cpp.

◆ free()

void ResourceRestrictionPolicy::free ( JobPointer )
overridevirtual

free() is called after the job has been executed.

It is guaranteed that free is called only after canRun() returned true at an earlier time.

Implements ThreadWeaver::QueuePolicy.

Definition at line 73 of file resourcerestrictionpolicy.cpp.

◆ release()

void ResourceRestrictionPolicy::release ( JobPointer )
overridevirtual

release() is called if canRun() returned true, but the job has not been executed for external reasons.

For example, a second QueuePolicy could have returned false from canRun() for the same job.

Implements ThreadWeaver::QueuePolicy.

Definition at line 84 of file resourcerestrictionpolicy.cpp.

◆ setCap()

void ResourceRestrictionPolicy::setCap ( int newCap)

Cap the number of simultaneously executing jobs.

Capping the amount of jobs will make sure that at max the number of jobs executing at any time is limited to the capped amount. Note that immediately after setting the amount of running jobs may be higher than the set amount. This setting only limits the starting of new jobs.

Parameters
newCapthe new cap to limit the amount of parallel jobs.

Definition at line 49 of file resourcerestrictionpolicy.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:06:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.