VirtualBox

Changeset 57629 in vbox


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

FE/Qt: Thread-pool: Get rid of friend classes.

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

Legend:

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

    r57626 r57629  
    114114}
    115115
     116bool UIThreadPool::isTerminating() const
     117{
     118    /* Acquire termination-flag: */
     119    m_everythingLocker.lock();
     120    bool fTerminating = m_fTerminating;
     121    m_everythingLocker.unlock();
     122
     123    return fTerminating;
     124}
     125
     126void UIThreadPool::setTerminating()
     127{
     128    m_everythingLocker.lock();
     129
     130    /* Indicate that we're terminating: */
     131    m_fTerminating = true;
     132
     133    /* Tell all threads to NOT queue any termination signals: */
     134    for (int idxWorker = 0; idxWorker < m_workers.size(); ++idxWorker)
     135    {
     136        UIThreadWorker *pWorker = m_workers[idxWorker];
     137        if (pWorker)
     138            pWorker->setNoFinishedSignal();
     139    }
     140
     141    /* Wake up all idle worker threads: */
     142    m_taskCondition.wakeAll();
     143
     144    m_everythingLocker.unlock();
     145}
     146
    116147void UIThreadPool::enqueueTask(UITask *pTask)
    117148{
     
    156187}
    157188
    158 /**
    159  * Checks if the thread pool is terminating.
    160  *
    161  * @returns @c true if terminating, @c false if not.
    162  * @note    Do NOT call this while owning the thread pool mutex!
    163  */
    164 bool UIThreadPool::isTerminating() const
    165 {
    166     /* Acquire termination-flag: */
    167     m_everythingLocker.lock();
    168     bool fTerminating = m_fTerminating;
    169     m_everythingLocker.unlock();
    170 
    171     return fTerminating;
    172 }
    173 
    174 void UIThreadPool::setTerminating()
    175 {
    176     m_everythingLocker.lock();
    177 
    178     /* Indicate that we're terminating: */
    179     m_fTerminating = true;
    180 
    181     /* Tell all threads to NOT queue any termination signals: */
    182     for (int idxWorker = 0; idxWorker < m_workers.size(); ++idxWorker)
    183     {
    184         UIThreadWorker *pWorker = m_workers[idxWorker];
    185         if (pWorker)
    186             pWorker->setNoFinishedSignal();
    187     }
    188 
    189     /* Wake up all idle worker threads: */
    190     m_taskCondition.wakeAll();
    191 
    192     m_everythingLocker.unlock();
    193 }
    194 
    195189UITask* UIThreadPool::dequeueTask(UIThreadWorker *pWorker)
    196190{
     
    263257}
    264258
    265 const QVariant& UITask::data() const
    266 {
    267     return m_data;
    268 }
    269 
    270259void UITask::start()
    271260{
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.h

    r57626 r57629  
    5252    ~UIThreadPool();
    5353
    54     /** Enqueues @a pTask into the task-queue. */
    55     void enqueueTask(UITask *pTask);
    56 
    5754    /** Returns whether the 'termination sequence' is started. */
    5855    bool isTerminating() const;
     
    6057    void setTerminating();
    6158
    62 protected:
    63 
     59    /** Enqueues @a pTask into the task-queue. */
     60    void enqueueTask(UITask *pTask);
    6461    /** Returns dequeued top-most task from the task-queue.
    6562      * @remarks Called by the @a pWorker passed as a hint. */
     
    109106      * all the inter-thread variables. */
    110107    mutable QMutex m_everythingLocker;
    111 
    112     /** Allows UIThreadWorker to dequeue tasks. */
    113     friend class UIThreadWorker;
    114108};
    115109
     
    133127
    134128    /** Returns the inter-thread task data. */
    135     const QVariant& data() const;
     129    const QVariant& data() const { return m_data; }
     130    /** Defines the inter-thread task @a data. */
     131    void setData(const QVariant &data) { m_data = data; }
     132
     133    /** Starts the task. */
     134    void start();
    136135
    137136protected:
    138 
    139     /** Starts the task.
    140       * @remarks Called by the worker-thread. */
    141     void start();
    142137
    143138    /** Contains the abstract task body.
     
    145140    virtual void run() = 0;
    146141
    147 //private:
     142private:
    148143
    149144    /** Holds the inter-thread task data. */
    150145    QVariant m_data;
    151 
    152     /** Allows UIThreadWorker to start task. */
    153     friend class UIThreadWorker;
    154146};
    155147
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp

    r57611 r57629  
    6161{
    6262    /* Get medium: */
    63     UIMedium medium = m_data.value<UIMedium>();
     63    UIMedium medium = data().value<UIMedium>();
    6464    /* Enumerate it: */
    6565    medium.blockAndQueryState();
    6666    /* Put medium back: */
    67     m_data = QVariant::fromValue(medium);
     67    setData(QVariant::fromValue(medium));
    6868}
    6969
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