VirtualBox

Changeset 57667 in vbox for trunk


Ignore:
Timestamp:
Sep 9, 2015 1:30:30 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: Thread-pool itself should delete processed tasks (instead of thread-pool client) after all listeners handled them.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

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

    r57663 r57667  
    112112    }
    113113
     114    /* Cleanup all the tasks: */
     115    qDeleteAll(m_pendingTasks);
     116    qDeleteAll(m_executingTasks);
     117    m_pendingTasks.clear();
     118    m_executingTasks.clear();
     119
    114120    /* Unlock finally: */
    115121    m_everythingLocker.unlock();
     
    167173
    168174    /* Put the task into the queue: */
    169     m_tasks.enqueue(pTask);
     175    m_pendingTasks.enqueue(pTask);
    170176
    171177    /* Wake up an idle worker if we got one: */
     
    216222
    217223        /* Dequeue task if there is one: */
    218         if (!m_tasks.isEmpty())
     224        if (!m_pendingTasks.isEmpty())
    219225        {
    220             UITask *pTask = m_tasks.dequeue();
     226            UITask *pTask = m_pendingTasks.dequeue();
    221227            if (pTask)
    222228            {
     229                /* Put into the set of executing tasks: */
     230                m_executingTasks << pTask;
     231
    223232                /* Unlock finally: */
    224233                m_everythingLocker.unlock();
     
    259268        return;
    260269
    261     /* Notify listener: */
     270    /* Notify listeners: */
    262271    emit sigTaskComplete(pTask);
     272
     273    /* Lock initially: */
     274    m_everythingLocker.lock();
     275
     276    /* Delete task finally: */
     277    Assert(m_executingTasks.contains(pTask) &&
     278           m_executingTasks.remove(pTask));
     279    delete pTask;
     280
     281    /* Unlock finally: */
     282    m_everythingLocker.unlock();
    263283}
    264284
     
    296316    {
    297317        /* Process the task if we are not terminating.
    298          * Please take into account tasks are cleared by their creator. */
     318         * Please take into account tasks are cleared by the UIThreadPool
     319         * after all listeners notified about task is complete and handled it. */
    299320        if (!m_pPool->isTerminating())
    300321            pTask->start();
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.h

    r57664 r57667  
    2323#include <QMutex>
    2424#include <QQueue>
     25#include <QSet>
    2526#include <QVariant>
    2627#include <QVector>
     
    9293    /** @name Task stuff
    9394     * @{ */
    94         /** Holds the queue (FIFO) of pending tasks. */
    95         QQueue<UITask*> m_tasks;
    96        /** Holds the condition variable that gets signalled when
     95        /** Holds the queue of pending tasks. */
     96        QQueue<UITask*> m_pendingTasks;
     97        /** Holds the set of executing tasks. */
     98        QSet<UITask*> m_executingTasks;
     99        /** Holds the condition variable that gets signalled when
    97100          * queuing a new task and there are idle worker threads around.
    98101          * @remarks Idle threads sits in dequeueTask waiting for this.
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp

    r57664 r57667  
    8484    /* Listen for global thread-pool: */
    8585    connect(vboxGlobal().threadPool(), SIGNAL(sigTaskComplete(UITask*)), this, SLOT(sltHandleMediumEnumerationTaskComplete(UITask*)));
    86 }
    87 
    88 UIMediumEnumerator::~UIMediumEnumerator()
    89 {
    90     /* Delete all the tasks: */
    91     while (!m_tasks.isEmpty())
    92         delete m_tasks.takeFirst();
    9386}
    9487
     
    276269    if (pTask->type() != UITask::Type_MediumEnumeration)
    277270        return;
    278     int iIndexOfTask = m_tasks.indexOf(pTask);
    279     AssertReturnVoid(iIndexOfTask != -1);
     271    AssertReturnVoid(m_tasks.contains(pTask));
    280272
    281273    /* Get enumerated UIMedium: */
     
    284276    LogRel2(("GUI: UIMediumEnumerator: Medium with key={%s} enumerated\n", strUIMediumKey.toAscii().constData()));
    285277
    286     /* Delete task: */
    287     delete m_tasks.takeAt(iIndexOfTask);
     278    /* Remove task from internal set: */
     279    m_tasks.remove(pTask);
    288280
    289281    /* Make sure such UIMedium still exists: */
     
    341333    /* Prepare medium-enumeration task: */
    342334    UITask *pTask = new UITaskMediumEnumeration(medium);
    343     /* Append to internal list: */
    344     m_tasks.append(pTask);
     335    /* Append to internal set: */
     336    m_tasks << pTask;
    345337    /* Post into global thread-pool: */
    346338    vboxGlobal().threadPool()->enqueueTask(pTask);
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.h

    r57611 r57667  
    2121/* Qt includes: */
    2222#include <QObject>
     23#include <QSet>
    2324
    2425/* GUI includes: */
     
    5354    /** Constructs medium-enumerator object. */
    5455    UIMediumEnumerator();
    55     /** Destructs medium-enumerator object. */
    56     ~UIMediumEnumerator();
    5756
    5857    /* API: Medium-access stuff: */
     
    9695    /* Variables: */
    9796    bool m_fMediumEnumerationInProgress;
    98     QList<UITask*> m_tasks;
     97    QSet<UITask*> m_tasks;
    9998    UIMediumMap m_mediums;
    10099};
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