VirtualBox

Changeset 57612 in vbox


Ignore:
Timestamp:
Sep 3, 2015 5:13:56 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: Thread-pool: Doxy.

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  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIThreadPool and UITask class implementation.
     3 * VBox Qt GUI - UIThreadPool and UITask classes implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2013 Oracle Corporation
     7 * Copyright (C) 2013-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.h

    r55401 r57612  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIThreadPool and UITask class declaration.
     3 * VBox Qt GUI - UIThreadPool and UITask classes declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2013 Oracle Corporation
     7 * Copyright (C) 2013-2015 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3131class UITask;
    3232
    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. */
    3535class UIThreadPool : public QObject
    3636{
     
    3939signals:
    4040
    41     /* Notifier: Task-queue stuff: */
     41    /** Notifies listeners about @a pTask complete. */
    4242    void sigTaskComplete(UITask *pTask);
    4343
    4444public:
    4545
    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. */
    4750    UIThreadPool(ulong cMaxWorkers = 3, ulong cMsWorkerIdleTimeout = 5000);
     51    /** Destructs worker-thread pool. */
    4852    ~UIThreadPool();
    4953
    50     /* API: Task-queue stuff: */
     54    /** Enqueues @a pTask into task-queue. */
    5155    void enqueueTask(UITask *pTask);
    5256
    53     /* API: Termination stuff: */
     57    /** Returns whether the 'termination sequence' is started. */
    5458    bool isTerminating() const;
     59    /** Defines that the 'termination sequence' is started. */
    5560    void setTerminating();
    5661
    5762protected:
    5863
    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. */
    6066    UITask* dequeueTask(UIThreadWorker *pWorker);
    6167
    6268private slots:
    6369
    64     /* Handler: Task-queue stuff: */
     70    /** Handles @a pTask complete signal. */
    6571    void sltHandleTaskComplete(UITask *pTask);
    6672
    67     /* Handler: Worker stuff: */
     73    /** Handles @a pWorker finished signal. */
    6874    void sltHandleWorkerFinished(UIThreadWorker *pWorker);
    6975
    7076private:
    7177
    72     /** @name Worker thread related variables.
     78    /** @name Worker-thread stuff.
    7379     * @{ */
    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;
    8593    /** @} */
    8694
    87     /** @name Task related variables
     95    /** @name Task stuff
    8896     * @{ */
    89     /** Queue (FIFO) of pending tasks. */
    90     QQueue<UITask*> m_tasks;
    91     /** Condition variable that gets signalled when queuing a new task and there are
    92      * idle worker threads around.
    93      *
    94      * Idle threads sits in dequeueTask waiting for this. Thus on thermination
    95      * setTerminating() will do a broadcast signal to wake up all workers (after
    96      * 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;
    98106    /** @} */
    99107
    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. */
    103110    mutable QMutex m_everythingLocker;
    104111
    105     /* Friends: */
     112    /** Allows UIThreadWorker to dequeue tasks. */
    106113    friend class UIThreadWorker;
    107114};
    108115
    109 /* GUI task interface.
    110  * Describes executable task to be used with UIThreadPool object. */
     116/** QObject extension used as worker-thread task.
     117  * Describes task to be executed by the UIThreadPool object. */
    111118class UITask : public QObject
    112119{
     
    115122signals:
    116123
    117     /* Notifier: Task stuff: */
     124    /** Notifies listeners about @a pTask complete. */
    118125    void sigComplete(UITask *pTask);
    119126
    120127public:
    121128
    122     /* Constructor: */
     129    /** Constructs worker-thread task.
     130      * @param data defines inter-thread task data to be processed by worker-thread. */
    123131    UITask(const QVariant &data);
    124132
    125     /* API: Data stuff: */
     133    /** Returns the inter-thread task data. */
    126134    const QVariant& data() const;
    127 
    128     /* API: Run stuff: */
    129     void start();
    130135
    131136protected:
    132137
    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. */
    134143    virtual void run() = 0;
    135144
    136     /* Variable: Data stuff: */
     145//private:
     146
     147    /** Holds the inter-thread task data to be processed by worker-thread. */
    137148    QVariant m_data;
     149
     150    /** Allows UIThreadWorker to start task. */
     151    friend class UIThreadWorker;
    138152};
    139153
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette