File indexing completed on 2024-04-28 15:34:50
0001 /* -*- C++ -*- 0002 This file declares the Collection class. 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 JOBCOLLECTION_H 0010 #define JOBCOLLECTION_H 0011 0012 #include "job.h" 0013 #include "jobpointer.h" 0014 0015 namespace ThreadWeaver 0016 { 0017 class Thread; 0018 class CollectionExecuteWrapper; 0019 0020 namespace Private 0021 { 0022 class Collection_Private; 0023 } 0024 0025 /** A Collection is a vector of Jobs that will be queued together. 0026 * In a Collection, the order of execution of the elements is not specified. 0027 * 0028 * It is intended that the collection is set up first and then 0029 * queued. After queuing, no further jobs should be added to the collection. 0030 */ 0031 class THREADWEAVER_EXPORT Collection : public Job 0032 { 0033 public: 0034 Collection(); 0035 Collection(ThreadWeaver::Private::Collection_Private *d); 0036 ~Collection() override; 0037 0038 /** Append a job to the collection. 0039 * 0040 * To use Collection, create the Job objects first, add them to the collection, and then queue it. After 0041 * the collection has been queued, no further Jobs are supposed to be added. 0042 * 0043 * @note Once the job has been added, execute wrappers can no more be set on it */ 0044 virtual void addJob(JobPointer); 0045 0046 /** Stop processing, dequeue all remaining Jobs. 0047 * job is supposed to be an element of the collection. 0048 */ 0049 // FIXME remove job argument? 0050 void stop(ThreadWeaver::JobPointer job); 0051 0052 /** Return the number of elements in the collection. */ 0053 int elementCount() const; 0054 0055 #if THREADWEAVER_ENABLE_DEPRECATED_SINCE(5, 0) 0056 /** @deprecated Since 5.0, use elementCount(). */ 0057 THREADWEAVER_DEPRECATED_VERSION(5, 0, "Use Collection::elementCount()") 0058 int jobListLength() const; 0059 #endif 0060 0061 /** @brief Add the job to this collection by pointer. */ 0062 Collection &operator<<(ThreadWeaver::JobInterface *job); 0063 0064 /** @brief Add the job to this collection. */ 0065 Collection &operator<<(const ThreadWeaver::JobPointer &job); 0066 Collection &operator<<(JobInterface &job); 0067 0068 protected: 0069 /** Overload to queue the collection. */ 0070 void aboutToBeQueued_locked(QueueAPI *api) override; 0071 0072 /** Overload to dequeue the collection. */ 0073 void aboutToBeDequeued_locked(QueueAPI *api) override; 0074 0075 /** Return a ref-erence to the job in the job list at position i. */ 0076 JobPointer jobAt(int i); 0077 0078 // FIXME remove 0079 /** Return the number of jobs in the joblist. 0080 * Assumes that the mutex is being held. 0081 */ 0082 virtual int jobListLength_locked() const; 0083 0084 protected: 0085 /** Overload the execute method. */ 0086 void execute(const JobPointer &job, Thread *) override; 0087 0088 /** Overload run(). 0089 * We have to. */ 0090 void run(JobPointer self, Thread *thread) override; 0091 0092 protected: 0093 friend class CollectionExecuteWrapper; // needs to access d() 0094 friend class Collection_Private; 0095 ThreadWeaver::Private::Collection_Private *d(); 0096 const ThreadWeaver::Private::Collection_Private *d() const; 0097 }; 0098 0099 } 0100 0101 #endif