File indexing completed on 2024-05-05 08:04:32
0001 /* -*- C++ -*- 0002 This file is part of ThreadWeaver. 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 WEAVER_P_H 0010 #define WEAVER_P_H 0011 0012 #include <QSemaphore> 0013 #include <QSharedPointer> 0014 #include <QWaitCondition> 0015 0016 #include "jobpointer.h" 0017 #include "state.h" 0018 #include "thread.h" 0019 0020 #include "queuesignals_p.h" 0021 0022 namespace ThreadWeaver 0023 { 0024 namespace Private 0025 { 0026 class Weaver_Private : public QueueSignals_Private 0027 { 0028 public: 0029 Weaver_Private(); 0030 ~Weaver_Private() override; 0031 0032 void dumpJobs(); 0033 0034 bool canBeExecuted(JobPointer); 0035 void deleteExpiredThreads(); 0036 0037 /** The thread inventory. */ 0038 QList<Thread *> inventory; 0039 /** Threads that have exited and can be deleted. */ 0040 QList<Thread *> expiredThreads; 0041 /** The job queue. */ 0042 QList<JobPointer> assignments; 0043 /** The number of jobs that are assigned to the worker threads, but not finished. */ 0044 int active; 0045 /** The maximum number of worker threads. */ 0046 int inventoryMax; 0047 /** Wait condition all idle or done threads wait for. */ 0048 QWaitCondition jobAvailable; 0049 /** Wait for a job to finish. */ 0050 QWaitCondition jobFinished; 0051 /** Mutex to serialize operations. */ 0052 QMutex *mutex; 0053 /** Semaphore to ensure thread startup is in sequence. */ 0054 QSemaphore semaphore; 0055 /** Before shutdown can proceed to close the running threads, it needs to ensure that all of them 0056 * entered the run method. */ 0057 QAtomicInt createdThreads; 0058 /** The state of the art. 0059 * @see StateId 0060 */ 0061 QAtomicPointer<State> state; 0062 /** The state objects. */ 0063 QSharedPointer<State> states[NoOfStates]; 0064 }; 0065 0066 } 0067 0068 } 0069 0070 #endif // WEAVER_P_H