• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

ThreadWeaver

  • threadweaver
  • Weaver
ResourceRestrictionPolicy.cpp
Go to the documentation of this file.
1/* -*- C++ -*-
2
3 This file implements the ResourceRestrictionPolicy class.
4
5 $ Author: Mirko Boehm $
6 $ Copyright: (C) 2004-2013 Mirko Boehm $
7 $ Contact: mirko@kde.org
8 http://www.kde.org
9 http://creative-destruction.me $
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Library General Public License for more details.
20
21 You should have received a copy of the GNU Library General Public License
22 along with this library; see the file COPYING.LIB. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA.
25
26 $Id: Job.h 32 2005-08-17 08:38:01Z mirko $
27*/
28
29#include "ResourceRestrictionPolicy.h"
30
31#include <QtCore/QList>
32#include <QtCore/QMutex>
33
34#include "DebuggingAids.h"
35
36using namespace ThreadWeaver;
37
38class ResourceRestrictionPolicy::Private
39{
40public:
41 Private ( int theCap )
42 : cap ( theCap)
43 {}
44
45 int cap;
46 QList<Job*> customers;
47 QMutex mutex;
48};
49
50ResourceRestrictionPolicy::ResourceRestrictionPolicy ( int cap)
51 : QueuePolicy ()
52 , d (new Private (cap))
53{
54}
55
56ResourceRestrictionPolicy::~ResourceRestrictionPolicy()
57{
58 delete d;
59}
60
61void ResourceRestrictionPolicy::setCap (int cap)
62{
63 QMutexLocker l ( & d->mutex );
64 d->cap = cap;
65}
66
67int ResourceRestrictionPolicy::cap() const
68{
69 QMutexLocker l ( & d->mutex );
70 return d->cap;
71}
72
73bool ResourceRestrictionPolicy::canRun( Job* job )
74{
75 QMutexLocker l ( & d->mutex );
76 if ( d->customers.size() < d->cap )
77 {
78 d->customers.append( job );
79 return true;
80 } else {
81 return false;
82 }
83}
84
85void ResourceRestrictionPolicy::free ( Job* job )
86{
87 QMutexLocker l ( & d->mutex );
88 int position = d->customers.indexOf (job);
89
90 if (position != -1)
91 {
92 debug ( 4, "ResourceRestrictionPolicy::free: job %p done.\n", (void*)job );
93 d->customers.removeAt (position);
94 }
95}
96
97void ResourceRestrictionPolicy::release ( Job* job )
98{
99 free (job);
100}
101
102void ResourceRestrictionPolicy::destructed ( Job* job )
103{
104 free (job);
105}
DebuggingAids.h
ResourceRestrictionPolicy.h
QList
Definition: DependencyPolicy.h:32
ThreadWeaver::Job
A Job is a simple abstraction of an action that is to be executed in a thread context.
Definition: Job.h:66
ThreadWeaver::QueuePolicy
QueuePolicy is an interface for customizations of the queueing behaviour of sets of jobs.
Definition: QueuePolicy.h:60
ThreadWeaver::ResourceRestrictionPolicy::destructed
void destructed(Job *)
destructing() is called when a Job that has this queue policy assigned gets destructed.
Definition: ResourceRestrictionPolicy.cpp:102
ThreadWeaver::ResourceRestrictionPolicy::~ResourceRestrictionPolicy
~ResourceRestrictionPolicy()
Definition: ResourceRestrictionPolicy.cpp:56
ThreadWeaver::ResourceRestrictionPolicy::cap
int cap() const
Definition: ResourceRestrictionPolicy.cpp:67
ThreadWeaver::ResourceRestrictionPolicy::canRun
bool canRun(Job *)
canRun() is called before the job is executed.
Definition: ResourceRestrictionPolicy.cpp:73
ThreadWeaver::ResourceRestrictionPolicy::ResourceRestrictionPolicy
ResourceRestrictionPolicy(int cap=0)
Definition: ResourceRestrictionPolicy.cpp:50
ThreadWeaver::ResourceRestrictionPolicy::setCap
void setCap(int newCap)
Cap the number of simulataniously executing jobs.
Definition: ResourceRestrictionPolicy.cpp:61
ThreadWeaver::ResourceRestrictionPolicy::release
void release(Job *)
release() is called if canRun() returned true, but the job has not been executed for external reasons...
Definition: ResourceRestrictionPolicy.cpp:97
ThreadWeaver::ResourceRestrictionPolicy::free
void free(Job *)
free() is called after the job has been executed.
Definition: ResourceRestrictionPolicy.cpp:85
ThreadWeaver
Definition: DebuggingAids.h:51
ThreadWeaver::debug
void debug(int severity, const char *cformat,...)
This method prints a text message on the screen, if debugging is enabled.
Definition: DebuggingAids.h:112
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ThreadWeaver

Skip menu "ThreadWeaver"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal