File indexing completed on 2024-04-21 04:01:29
0001 /* -*- C++ -*- 0002 This file declares the StateIMplementation class. 0003 0004 SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef WEAVERIMPLSTATE_H 0010 #define WEAVERIMPLSTATE_H 0011 0012 #include "state.h" 0013 #include "weaver.h" 0014 0015 namespace ThreadWeaver 0016 { 0017 class QueueSignals; 0018 0019 /** @brief Base class for all WeaverImpl states. */ 0020 class WeaverImplState : public State 0021 { 0022 public: 0023 explicit WeaverImplState(QueueSignals *weaver); 0024 0025 const State *state() const override; 0026 0027 /** Shut down the queue. */ 0028 void shutDown() override; 0029 /** Set the maximum number of threads this Weaver object may start. */ 0030 void setMaximumNumberOfThreads(int cap) override; 0031 /** Get the maximum number of threads this Weaver may start. */ 0032 int maximumNumberOfThreads() const override; 0033 /** Returns the current number of threads in the inventory. */ 0034 int currentNumberOfThreads() const override; 0035 /** Enqueue a job. */ 0036 void enqueue(const QList<JobPointer> &jobs) override; 0037 /** Dequeue a job. */ 0038 bool dequeue(const JobPointer &job) override; 0039 /** Dequeue all jobs. */ 0040 void dequeue() override; 0041 /** Finish all queued jobs. */ 0042 void finish() override; 0043 /** Are no more jobs queued? */ 0044 bool isEmpty() const override; 0045 /** Are all threads waiting? */ 0046 bool isIdle() const override; 0047 /** How many jobs are currently queued? */ 0048 int queueLength() const override; 0049 /** Request abort for all queued and currently executed jobs. */ 0050 void requestAbort() override; 0051 /** Reschedule jobs to threads. */ 0052 void reschedule() override; 0053 /** Wait (by suspending the calling thread) until a job becomes available. */ 0054 void waitForAvailableJob(Thread *th) override; 0055 0056 protected: 0057 /** Provide correct return type for WeaverImpl states. */ 0058 Weaver *weaver() override; 0059 const Weaver *weaver() const override; 0060 }; 0061 0062 } 0063 0064 #endif