VirtualBox

Ignore:
Timestamp:
Oct 7, 2013 12:01:17 AM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: UIThreadPool: Small after-inspection cleanup.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/globals
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.cpp

    r48910 r48911  
    3030#include <VBox/sup.h>
    3131
    32 /** @todo r=bird: this code was racy, inefficient and buggy in it's first
    33  *        incarnation.  What is required from RTReqPool for it to replace the
    34  *        internals here?  COM init/term hooks, sure. Does the threads need to
    35  *        be QThreads? */
    36 
    37 
    3832/**
    3933 * COM capable worker thread for the UIThreadPool.
     
    5549    int getIndex() const { return m_iIndex; }
    5650
    57     /** Disables sigFinished.  For optimizing pool termination. */
     51    /** Disables sigFinished. For optimizing pool termination. */
    5852    void setNoFinishedSignal()
    5953    {
     
    7670
    7771
    78 UIThreadPool::UIThreadPool(ulong cMaxWorkers/* = 3*/, ulong cMsWorkerIdleTimeout /* = 5000*/)
     72UIThreadPool::UIThreadPool(ulong cMaxWorkers /* = 3 */, ulong cMsWorkerIdleTimeout /* = 5000 */)
    7973    : m_workers(cMaxWorkers)
    8074    , m_cMsIdleTimeout(cMsWorkerIdleTimeout)
     
    8276    , m_cIdleWorkers(0)
    8377    , m_fTerminating(false) /* termination status */
    84     , m_everythingLocker(QMutex::NonRecursive)
    8578{
    8679}
     
    9184    setTerminating();
    9285
     86    m_everythingLocker.lock(); /* paranoia */
     87
    9388    /* Cleanup all the workers: */
    94     m_everythingLocker.lock(); /* paranoia */
    9589    for (int idxWorker = 0; idxWorker < m_workers.size(); ++idxWorker)
    9690    {
     
    134128    else if (m_cWorkers < m_workers.size())
    135129    {
    136         /* Find free slot. */
     130        /* Find free slot: */
    137131        int idxFirstUnused = m_workers.size();
    138132        while (idxFirstUnused-- > 0)
     
    165159{
    166160    /* Acquire termination-flag: */
    167     QMutexLocker lock(&m_everythingLocker);
     161    m_everythingLocker.lock();
    168162    bool fTerminating = m_fTerminating;
    169     lock.unlock();
     163    m_everythingLocker.unlock();
    170164
    171165    return fTerminating;
     
    195189UITask* UIThreadPool::dequeueTask(UIThreadWorker *pWorker)
    196190{
    197     /*
    198      * Dequeue a task, watching out for terminations. For opimal efficiency in
    199      * enqueueTask() we keep count of idle threads.
    200      *
    201      * If the wait times out, we'll return NULL and terminate the thread.
    202      */
     191    /* Dequeue a task, watching out for terminations.
     192     * For opimal efficiency in enqueueTask() we keep count of idle threads.
     193     * If the wait times out, we'll return NULL and terminate the thread. */
    203194    m_everythingLocker.lock();
    204195
     
    219210        }
    220211
    221         /* If we timed out already, then quit the worker thread.  To prevent a
     212        /* If we timed out already, then quit the worker thread. To prevent a
    222213           race between enqueueTask and the queue removal of the thread from
    223            the workers vector, we remove it here already.  (This does not apply
     214           the workers vector, we remove it here already. (This does not apply
    224215           to the termination scenario.) */
    225216        if (fIdleTimedOut)
     
    254245{
    255246    /* Wait for the thread to finish completely, then delete the thread
    256        object.  We have already removed the thread from the workers vector.
     247       object. We have already removed the thread from the workers vector.
    257248       Note! We don't want to use 'this' here, in case it's invalid. */
    258249    pWorker->wait();
     
    289280void UIThreadWorker::run()
    290281{
    291 //    LogRelFlow(("UIThreadWorker #%d: Started...\n", m_iIndex));
    292 
    293282    /* Initialize COM: */
    294283    COMBase::InitializeCOM(false);
     
    297286    while (UITask *pTask = m_pPool->dequeueTask(this))
    298287    {
    299         /* Process task: */
    300 //        LogRelFlow(("UIThreadWorker #%d: Task acquired...\n", m_iIndex));
     288        /* Process the task if we are not terminating.
     289         * Please take into account tasks are cleared by their creator. */
    301290        if (!m_pPool->isTerminating())
    302291            pTask->start();
    303         /** @todo else: Just leak the task? */
    304 //        LogRelFlow(("UIThreadWorker #%d: Task processed!\n", m_iIndex));
    305292    }
    306293
     
    312299    if (!m_fNoFinishedSignal)
    313300        emit sigFinished(this);
    314 
    315 //    LogRelFlow(("UIThreadWorker #%d: Finished!\n", m_iIndex));
    316301}
    317302
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.h

    r48908 r48911  
    5757
    5858    /* Protected API: Worker-thread stuff: */
    59     UITask *dequeueTask(UIThreadWorker *pWorker);
     59    UITask* dequeueTask(UIThreadWorker *pWorker);
    6060
    6161private slots:
     
    6868
    6969private:
     70
    7071    /** @name Worker thread related variables.
    7172     * @{ */
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