ThreadWeaver

weaverimplstate.cpp
1/* -*- C++ -*-
2 This file implements the StateImplementation class.
3
4 SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org>
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
13namespace ThreadWeaver
14{
15WeaverImplState::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
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
62bool WeaverImplState::dequeue(const JobPointer &job)
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{
104 weaver()->blockThreadUntilJobsAreBeingAssigned(th);
105}
106
107}
QueueSignals declares the Qt signals shared by the Queue and Weaver classes.
We use a State pattern to handle the system state in ThreadWeaver.
Definition state.h:56
virtual QueueInterface * weaver()
The Weaver interface this state handles.
Definition state.cpp:49
State(QueueSignals *weaver)
Default constructor.
Definition state.cpp:30
Thread represents a worker thread in a Queue's inventory.
Definition thread.h:28
void finish() override
Finish all queued jobs.
int queueLength() const override
How many jobs are currently queued?
void reschedule() override
Reschedule jobs to threads.
int currentNumberOfThreads() const override
Returns the current number of threads in the inventory.
Weaver * weaver() override
Provide correct return type for WeaverImpl states.
void enqueue(const QList< JobPointer > &jobs) override
Enqueue a job.
void waitForAvailableJob(Thread *th) override
Wait (by suspending the calling thread) until a job becomes available.
const State * state() const override
Return the state of the weaver object.
bool isIdle() const override
Are all threads waiting?
void shutDown() override
Shut down the queue.
void requestAbort() override
Request abort for all queued and currently executed jobs.
void setMaximumNumberOfThreads(int cap) override
Set the maximum number of threads this Weaver object may start.
int maximumNumberOfThreads() const override
Get the maximum number of threads this Weaver may start.
bool isEmpty() const override
Are no more jobs queued?
bool dequeue(const JobPointer &job) override
Dequeue a job.
A Weaver manages worker threads.
Definition weaver.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:57:09 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.