ThreadWeaver
#include <ResourceRestrictionPolicy.h>
Public Member Functions | |
ResourceRestrictionPolicy (int cap=0) | |
~ResourceRestrictionPolicy () | |
bool | canRun (Job *) |
int | cap () const |
void | destructed (Job *) |
void | free (Job *) |
void | release (Job *) |
void | setCap (int newCap) |
Public Member Functions inherited from ThreadWeaver::QueuePolicy | |
virtual | ~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 resurce 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 SMIV 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 54 of file ResourceRestrictionPolicy.h.
Constructor & Destructor Documentation
|
explicit |
Definition at line 50 of file ResourceRestrictionPolicy.cpp.
ResourceRestrictionPolicy::~ResourceRestrictionPolicy | ( | ) |
Definition at line 56 of file ResourceRestrictionPolicy.cpp.
Member Function Documentation
|
virtual |
canRun() is called before the job is executed.
The job will only be executed if canRun() returns true.
Implements ThreadWeaver::QueuePolicy.
Definition at line 73 of file ResourceRestrictionPolicy.cpp.
int ResourceRestrictionPolicy::cap | ( | ) | const |
Definition at line 67 of file ResourceRestrictionPolicy.cpp.
|
virtual |
destructing() is called when a Job that has this queue policy assigned gets destructed.
Implements ThreadWeaver::QueuePolicy.
Definition at line 102 of file ResourceRestrictionPolicy.cpp.
|
virtual |
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 85 of file ResourceRestrictionPolicy.cpp.
|
virtual |
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 97 of file ResourceRestrictionPolicy.cpp.
void ResourceRestrictionPolicy::setCap | ( | int | newCap | ) |
Cap the number of simulataniously 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
-
newCap the new cap to limit the amount of parallel jobs.
Definition at line 61 of file ResourceRestrictionPolicy.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.