Changeset 57612 in vbox
- Timestamp:
- Sep 3, 2015 5:13:56 PM (9 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/globals
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.cpp
r54554 r57612 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIThreadPool and UITask class implementation.3 * VBox Qt GUI - UIThreadPool and UITask classes implementation. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2013 Oracle Corporation7 * Copyright (C) 2013-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.h
r55401 r57612 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UIThreadPool and UITask class declaration.3 * VBox Qt GUI - UIThreadPool and UITask classes declaration. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2013 Oracle Corporation7 * Copyright (C) 2013-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 31 31 class UITask; 32 32 33 /* Worker-thread pool prototype.34 * Schedules COM-related GUI tasks to multiple worker-threads. */33 /** QObject extension used as worker-thread pool. 34 * Schedules COM-related GUI tasks to multiple worker-threads. */ 35 35 class UIThreadPool : public QObject 36 36 { … … 39 39 signals: 40 40 41 /* Notifier: Task-queue stuff:*/41 /** Notifies listeners about @a pTask complete. */ 42 42 void sigTaskComplete(UITask *pTask); 43 43 44 44 public: 45 45 46 /* Constructor/destructor: */ 46 /** Constructs worker-thread pool. 47 * @param cMaxWorkers defines the maximum amount of worker-threads. 48 * @param cMsWorkerIdleTimeout defines the maximum amount of time (in ms) which 49 * pool will wait for the worker-thread on cleanup. */ 47 50 UIThreadPool(ulong cMaxWorkers = 3, ulong cMsWorkerIdleTimeout = 5000); 51 /** Destructs worker-thread pool. */ 48 52 ~UIThreadPool(); 49 53 50 /* API: Task-queue stuff:*/54 /** Enqueues @a pTask into task-queue. */ 51 55 void enqueueTask(UITask *pTask); 52 56 53 /* API: Termination stuff:*/57 /** Returns whether the 'termination sequence' is started. */ 54 58 bool isTerminating() const; 59 /** Defines that the 'termination sequence' is started. */ 55 60 void setTerminating(); 56 61 57 62 protected: 58 63 59 /* Protected API: Worker-thread stuff: */ 64 /** Returns dequeued top-most task from the task-queue using @a pWorker as a hint. 65 * @remarks Called by the worker-thread. */ 60 66 UITask* dequeueTask(UIThreadWorker *pWorker); 61 67 62 68 private slots: 63 69 64 /* Handler: Task-queue stuff:*/70 /** Handles @a pTask complete signal. */ 65 71 void sltHandleTaskComplete(UITask *pTask); 66 72 67 /* Handler: Worker stuff:*/73 /** Handles @a pWorker finished signal. */ 68 74 void sltHandleWorkerFinished(UIThreadWorker *pWorker); 69 75 70 76 private: 71 77 72 /** @name Worker thread related variables.78 /** @name Worker-thread stuff. 73 79 * @{ */ 74 QVector<UIThreadWorker*> m_workers; 75 /** Milliseconds */ 76 const ulong m_cMsIdleTimeout; 77 /** The number of worker threads. 78 * @remarks We cannot use the vector size since it may contain NULL pointers. */ 79 int m_cWorkers; 80 /** The number of idle worker threads. */ 81 int m_cIdleWorkers; 82 /** Set by the destructor to indicate that all worker threads should 83 * terminate ASAP. */ 84 bool m_fTerminating; 80 /** Holds the maximum amount of time (in ms) which 81 * pool will wait for the worker-thread on cleanup. */ 82 const ulong m_cMsIdleTimeout; 83 /** Holds the vector of worker-threads. */ 84 QVector<UIThreadWorker*> m_workers; 85 /** Holds the number of worker-threads. 86 * @remarks We cannot use the vector size since it may contain NULL pointers. */ 87 int m_cWorkers; 88 /** Holds the number of idle worker-threads. */ 89 int m_cIdleWorkers; 90 /** Holds whether the 'termination sequence' is started 91 * and all worker-threads should terminate ASAP. */ 92 bool m_fTerminating; 85 93 /** @} */ 86 94 87 /** @name Task related variables95 /** @name Task stuff 88 96 * @{ */ 89 /** Queue (FIFO) of pending tasks. */90 QQueue<UITask*> m_tasks;91 /** Condition variable that gets signalled when queuing a new task and there are92 *idle worker threads around.93 *94 * Idle threads sits in dequeueTask waiting for this. Thus on thermination95 * setTerminating() will do abroadcast signal to wake up all workers (after96 *setting m_fTerminating of course). */97 QWaitCondition m_taskCondition;97 /** Holds the queue (FIFO) of pending tasks. */ 98 QQueue<UITask*> m_tasks; 99 /** Holds the condition variable that gets signalled when 100 * queuing a new task and there are idle worker threads around. 101 * @remarks Idle threads sits in dequeueTask waiting for this. 102 * Thus on thermination, setTerminating() will send a 103 * broadcast signal to wake up all workers (after 104 * setting m_fTerminating of course). */ 105 QWaitCondition m_taskCondition; 98 106 /** @} */ 99 107 100 101 /** This mutex is used with the m_taskCondition condition and protects m_tasks, 102 * m_fTerminating and m_workers. */ 108 /** Holds the guard mutex object protecting 109 * all the inter-thread variables. */ 103 110 mutable QMutex m_everythingLocker; 104 111 105 /* Friends:*/112 /** Allows UIThreadWorker to dequeue tasks. */ 106 113 friend class UIThreadWorker; 107 114 }; 108 115 109 /* GUI task interface.110 * Describes executable task to be used withUIThreadPool object. */116 /** QObject extension used as worker-thread task. 117 * Describes task to be executed by the UIThreadPool object. */ 111 118 class UITask : public QObject 112 119 { … … 115 122 signals: 116 123 117 /* Notifier: Task stuff:*/124 /** Notifies listeners about @a pTask complete. */ 118 125 void sigComplete(UITask *pTask); 119 126 120 127 public: 121 128 122 /* Constructor: */ 129 /** Constructs worker-thread task. 130 * @param data defines inter-thread task data to be processed by worker-thread. */ 123 131 UITask(const QVariant &data); 124 132 125 /* API: Data stuff:*/133 /** Returns the inter-thread task data. */ 126 134 const QVariant& data() const; 127 128 /* API: Run stuff: */129 void start();130 135 131 136 protected: 132 137 133 /* Helper: Run stuff: */ 138 /** Starts the task. 139 * @remarks Called by the worker-thread. */ 140 void start(); 141 142 /** Contains the abstract task body, to be reimplemented in sub-class. */ 134 143 virtual void run() = 0; 135 144 136 /* Variable: Data stuff: */ 145 //private: 146 147 /** Holds the inter-thread task data to be processed by worker-thread. */ 137 148 QVariant m_data; 149 150 /** Allows UIThreadWorker to start task. */ 151 friend class UIThreadWorker; 138 152 }; 139 153
Note:
See TracChangeset
for help on using the changeset viewer.