| 1 | /* -*- C++ -*- |
| 2 | This file declares 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 | |
| 9 | #ifndef WEAVERIMPLSTATE_H |
| 10 | #define WEAVERIMPLSTATE_H |
| 11 | |
| 12 | #include "state.h" |
| 13 | #include "weaver.h" |
| 14 | |
| 15 | namespace ThreadWeaver |
| 16 | { |
| 17 | class QueueSignals; |
| 18 | |
| 19 | /* |
| 20 | * Base class for all WeaverImpl states. |
| 21 | */ |
| 22 | class WeaverImplState : public State |
| 23 | { |
| 24 | public: |
| 25 | explicit WeaverImplState(QueueSignals *weaver); |
| 26 | |
| 27 | const State *state() const override; |
| 28 | |
| 29 | /* Shut down the queue. */ |
| 30 | void shutDown() override; |
| 31 | /* Set the maximum number of threads this Weaver object may start. */ |
| 32 | void setMaximumNumberOfThreads(int cap) override; |
| 33 | /* Get the maximum number of threads this Weaver may start. */ |
| 34 | int maximumNumberOfThreads() const override; |
| 35 | /* Returns the current number of threads in the inventory. */ |
| 36 | int currentNumberOfThreads() const override; |
| 37 | /* Enqueue a job. */ |
| 38 | void enqueue(const QList<JobPointer> &jobs) override; |
| 39 | /* Dequeue a job. */ |
| 40 | bool dequeue(const JobPointer &job) override; |
| 41 | /* Dequeue all jobs. */ |
| 42 | void dequeue() override; |
| 43 | /* Finish all queued jobs. */ |
| 44 | void finish() override; |
| 45 | /* Are no more jobs queued? */ |
| 46 | bool isEmpty() const override; |
| 47 | /* Are all threads waiting? */ |
| 48 | bool isIdle() const override; |
| 49 | /* How many jobs are currently queued? */ |
| 50 | int queueLength() const override; |
| 51 | /* Request abort for all queued and currently executed jobs. */ |
| 52 | void requestAbort() override; |
| 53 | /* Reschedule jobs to threads. */ |
| 54 | void reschedule() override; |
| 55 | /* Wait (by suspending the calling thread) until a job becomes available. */ |
| 56 | void waitForAvailableJob(Thread *th) override; |
| 57 | |
| 58 | protected: |
| 59 | /* Provide correct return type for WeaverImpl states. */ |
| 60 | Weaver *weaver() override; |
| 61 | const Weaver *weaver() const override; |
| 62 | }; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | #endif |
| 67 | |