ThreadWeaver 5.109.0
|
ResourceRestrictionPolicy is used to limit the number of concurrent accesses to the same resource. More...
#include <resourcerestrictionpolicy.h>
Public Member Functions | |
ResourceRestrictionPolicy (int cap=0) | |
bool | canRun (JobPointer) override |
canRun() is called before the job is executed. | |
int | cap () const |
void | destructed (JobInterface *job) override |
destructing() is called when a Job that has this queue policy assigned gets destructed. | |
void | free (JobPointer) override |
free() is called after the job has been executed. | |
void | release (JobPointer) override |
release() is called if canRun() returned true, but the job has not been executed for external reasons. | |
void | setCap (int newCap) |
Cap the number of simultaneously executing jobs. | |
virtual bool | canRun (JobPointer)=0 |
canRun() is called before the job is executed. | |
virtual void | destructed (JobInterface *job)=0 |
destructing() is called when a Job that has this queue policy assigned gets destructed. | |
virtual void | free (JobPointer)=0 |
free() is called after the job has been executed. | |
virtual void | release (JobPointer)=0 |
release() is called if canRun() returned true, but the job has not been executed for external reasons. | |
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.
|
overridevirtual |
canRun() is called before the job is executed.
The job will only be executed if canRun() returns true.
Implements ThreadWeaver::QueuePolicy.
|
overridevirtual |
destructing() is called when a Job that has this queue policy assigned gets destructed.
Implements ThreadWeaver::QueuePolicy.
|
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.
|
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.
void ThreadWeaver::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.
newCap | the new cap to limit the amount of parallel jobs. |