ThreadWeaver

weaverimplstate.cpp
1 /* -*- C++ -*-
2  This file implements the StateImplementation class.
3 
4  SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 
8  $Id: InConstructionState.cpp 30 2005-08-16 16:16:04Z mirko $
9 */
10 
11 #include "weaverimplstate.h"
12 
13 namespace ThreadWeaver
14 {
15 WeaverImplState::WeaverImplState(QueueSignals *weaver)
16  : State(weaver)
17 {
18 }
19 
21 {
22  return this;
23 }
24 
26 {
27  weaver()->shutDown_p();
28 }
29 
31 {
32  Q_ASSERT(dynamic_cast<Weaver *>(State::weaver()));
33  return static_cast<Weaver *>(State::weaver());
34 }
35 
36 const Weaver *WeaverImplState::weaver() const
37 {
38  Q_ASSERT(dynamic_cast<const Weaver *>(State::weaver()));
39  return static_cast<const Weaver *>(State::weaver());
40 }
41 
43 {
44  weaver()->setMaximumNumberOfThreads_p(cap);
45 }
46 
48 {
49  return weaver()->maximumNumberOfThreads_p();
50 }
51 
53 {
54  return weaver()->currentNumberOfThreads_p();
55 }
56 
58 {
59  weaver()->enqueue_p(jobs);
60 }
61 
63 {
64  return weaver()->dequeue_p(job);
65 }
66 
68 {
69  weaver()->dequeue_p();
70 }
71 
73 {
74  weaver()->finish_p();
75 }
76 
78 {
79  return weaver()->isEmpty_p();
80 }
81 
83 {
84  return weaver()->isIdle_p();
85 }
86 
88 {
89  return weaver()->queueLength_p();
90 }
91 
93 {
94  return weaver()->requestAbort_p();
95 }
96 
98 {
99  // Not implemented, performed directly in Weaver::reschedule().
100 }
101 
103 {
105 }
106 
107 }
void enqueue(const QVector< JobPointer > &jobs) override
Enqueue a job.
void blockThreadUntilJobsAreBeingAssigned(Thread *th)
Blocks the calling thread until jobs can be assigned.
Definition: weaver.cpp:585
int currentNumberOfThreads() const override
Returns the current number of threads in the inventory.
bool isEmpty() const override
Are no more jobs queued?
void reschedule() override
Reschedule jobs to threads.
A Weaver manages worker threads.
Definition: weaver.h:34
void setMaximumNumberOfThreads(int cap) override
Set the maximum number of threads this Weaver object may start.
Weaver * weaver() override
Provide correct return type for WeaverImpl states.
void waitForAvailableJob(Thread *th) override
Wait (by suspending the calling thread) until a job becomes available.
int queueLength() const override
How many jobs are currently queued?
const State * state() const override
Return the state of the weaver object.
void finish() override
Finish all queued jobs.
int maximumNumberOfThreads() const override
Get the maximum number of threads this Weaver may start.
We use a State pattern to handle the system state in ThreadWeaver.
Definition: state.h:55
void dequeue() override
Dequeue all jobs.
bool isIdle() const override
Are all threads waiting?
Thread represents a worker thread in a Queue's inventory.
Definition: thread.h:27
virtual QueueInterface * weaver()
The Weaver interface this state handles.
Definition: state.cpp:49
void shutDown() override
Shut down the queue.
void requestAbort() override
Request abort for all queued and currently executed jobs.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:09:38 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.