File indexing completed on 2024-04-28 15:34:50
0001 /* -*- C++ -*- 0002 This file is part of ThreadWeaver. 0003 0004 SPDX-FileCopyrightText: 2004-2013 Mirko Boehm <mirko@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef COLLECTION_COLLECTION_P_H 0010 #define COLLECTION_COLLECTION_P_H 0011 0012 #include <QMutex> 0013 #include <QVector> 0014 0015 #include "executewrapper_p.h" 0016 #include "job_p.h" 0017 0018 namespace ThreadWeaver 0019 { 0020 class Collection; 0021 0022 namespace Private 0023 { 0024 class CollectionSelfExecuteWrapper : public ThreadWeaver::ExecuteWrapper 0025 { 0026 public: 0027 void begin(const JobPointer &, Thread *) override; 0028 void end(const JobPointer &, Thread *) override; 0029 0030 void callBegin(); 0031 void callEnd(); 0032 0033 private: 0034 JobPointer job_; 0035 Thread *thread_; 0036 }; 0037 0038 class Collection_Private : public Job_Private 0039 { 0040 public: 0041 Collection_Private(); 0042 ~Collection_Private() override; 0043 0044 /** Dequeue all elements of the collection. 0045 * Note: This will not dequeue the collection itself. 0046 */ 0047 void dequeueElements(Collection *collection, bool queueApiIsLocked); 0048 0049 /** Perform the task usually done when one individual job is 0050 * finished, but in our case only when the whole collection 0051 * is finished or partly dequeued. 0052 */ 0053 void finalCleanup(Collection *collection); 0054 0055 /** @brief Enqueue the elements of the collection. */ 0056 void enqueueElements(); 0057 0058 void elementStarted(Collection *collection, JobPointer, Thread *); 0059 void elementFinished(Collection *collection, JobPointer job, Thread *thread); 0060 0061 /** @brief Prepare to enqueue the elements. */ 0062 virtual void prepareToEnqueueElements(); 0063 0064 /** @brief Process a completed element. */ 0065 virtual void processCompletedElement(Collection *collection, JobPointer job, Thread *thread); 0066 0067 /** @brief Implement stop. */ 0068 void stop_locked(Collection *collection); 0069 0070 /** @brief Called before an element will be dequeued. */ 0071 virtual void elementDequeued(const JobPointer &) 0072 { 0073 } 0074 0075 /* The elements of the collection. */ 0076 QVector<JobPointer> elements; 0077 0078 /* The Weaver interface this collection is queued in. */ 0079 QueueAPI *api; 0080 0081 /* Counter for the finished jobs. 0082 Set to the number of elements when started. 0083 When zero, all elements are done. 0084 */ 0085 QAtomicInt jobCounter; 0086 QAtomicInt jobsStarted; 0087 CollectionSelfExecuteWrapper selfExecuteWrapper; 0088 JobPointer self; 0089 bool selfIsExecuting; 0090 }; 0091 0092 } 0093 0094 } 0095 0096 #endif // COLLECTION_COLLECTION_P_H