VirtualBox

Changeset 41042 in vbox for trunk/src


Ignore:
Timestamp:
Apr 24, 2012 10:39:09 AM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: Settings serializer refactoring, fixed bug with settings serializer crushing on ACPI shutdown (#6141).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp

    r39968 r41042  
    7474    Q_OBJECT;
    7575
     76signals:
     77
     78    /* Signal to notify main GUI thread about process has been started: */
     79    void sigNotifyAboutProcessStarted();
     80
     81    /* Signal to notify main GUI thread about some page was processed: */
     82    void sigNotifyAboutPageProcessed(int iPageId);
     83
     84    /* Signal to notify main GUI thread about all pages were processed: */
     85    void sigNotifyAboutPagesProcessed();
     86
    7687public:
    7788
     
    8495        , m_direction(direction)
    8596        , m_data(data)
    86         , m_fConditionDone(false)
    87         , m_fAllowToDestroySerializer(false)
    88         , m_iPageIdWeAreWaitingFor(-1)
     97        , m_fSavingComplete(m_direction == UISettingsSerializeDirection_Load)
     98        , m_fAllowToDestroySerializer(m_direction == UISettingsSerializeDirection_Load)
    8999        , m_iIdOfHighPriorityPage(-1)
    90100    {
     101        /* Set instance: */
     102        m_pInstance = this;
     103
    91104        /* Connecting this signals: */
    92105        connect(this, SIGNAL(sigNotifyAboutPageProcessed(int)), this, SLOT(sltHandleProcessedPage(int)), Qt::QueuedConnection);
     
    96109        connect(this, SIGNAL(sigNotifyAboutProcessStarted()), parent(), SLOT(sltHandleProcessStarted()), Qt::QueuedConnection);
    97110        connect(this, SIGNAL(sigNotifyAboutPageProcessed(int)), parent(), SLOT(sltHandlePageProcessed()), Qt::QueuedConnection);
    98 
    99         /* Set instance: */
    100         m_pInstance = this;
    101111    }
    102112
     
    104114    ~UISettingsSerializer()
    105115    {
    106         /* Reset instance: */
    107         m_pInstance = 0;
    108 
    109116        /* If serializer is being destructed by it's parent,
    110117         * thread could still be running, we have to wait
     
    112119        if (isRunning())
    113120            wait();
     121
     122        /* Clear instance: */
     123        m_pInstance = 0;
    114124    }
    115125
     
    124134    }
    125135
    126     /* Blocks calling thread until requested page will be processed: */
    127     void waitForPageToBeProcessed(int iPageId)
    128     {
    129         m_iPageIdWeAreWaitingFor = iPageId;
    130         blockGUIthread();
    131     }
    132 
    133     /* Blocks calling thread until all pages will be processed: */
    134     void waitForPagesToBeProcessed()
    135     {
    136         m_iPageIdWeAreWaitingFor = -1;
    137         blockGUIthread();
    138     }
    139 
    140136    /* Raise priority of page: */
    141137    void raisePriorityOfPage(int iPageId)
     
    157153    QVariant& data() { return m_data; }
    158154
    159 signals:
    160 
    161     /* Signal to notify main GUI thread about process has been started: */
    162     void sigNotifyAboutProcessStarted();
    163 
    164     /* Signal to notify main GUI thread about some page was processed: */
    165     void sigNotifyAboutPageProcessed(int iPageId);
    166 
    167     /* Signal to notify main GUI thread about all pages were processed: */
    168     void sigNotifyAboutPagesProcessed();
    169 
    170155public slots:
    171156
    172157    void start(Priority priority = InheritPriority)
    173158    {
    174         /* Notify listeners a bout we are starting: */
     159        /* Notify listeners about we are starting: */
    175160        emit sigNotifyAboutProcessStarted();
     161
    176162        /* If serializer saves settings: */
    177163        if (m_direction == UISettingsSerializeDirection_Save)
     
    181167                m_pages.values()[iPageIndex]->putToCache();
    182168        }
    183         /* Start async thread: */
     169
     170        /* Start async serializing thread: */
    184171        QThread::start(priority);
     172
     173        /* If serializer saves settings: */
     174        if (m_direction == UISettingsSerializeDirection_Save)
     175        {
     176            /* We should block calling thread until all pages will be saved: */
     177            while (!m_fSavingComplete)
     178            {
     179                /* Lock mutex initially: */
     180                m_mutex.lock();
     181                /* Perform idle-processing every 100ms,
     182                 * and waiting for direct wake up signal: */
     183                m_condition.wait(&m_mutex, 100);
     184                /* Process queued signals posted to GUI thread: */
     185                qApp->processEvents();
     186                /* Unlock mutex finally: */
     187                m_mutex.unlock();
     188            }
     189            m_fAllowToDestroySerializer = true;
     190        }
    185191    }
    186192
     
    197203                m_pages[iPageId]->getFromCache();
    198204        }
    199         /* If thats the page we are waiting for,
    200          * we should flag GUI thread to unlock itself: */
    201         if (iPageId == m_iPageIdWeAreWaitingFor && !m_fConditionDone)
    202             m_fConditionDone = true;
    203     }
    204 
    205     /* Slot to handle the fact of some page was processed: */
     205    }
     206
     207    /* Slot to handle the fact of all pages were processed: */
    206208    void sltHandleProcessedPages()
    207209    {
    208         /* We should flag GUI thread to unlock itself: */
    209         if (!m_fConditionDone)
    210             m_fConditionDone = true;
     210        /* If serializer saves settings: */
     211        if (m_direction == UISettingsSerializeDirection_Save)
     212        {
     213            /* We should flag GUI thread to unlock itself: */
     214            if (!m_fSavingComplete)
     215                m_fSavingComplete = true;
     216        }
    211217    }
    212218
     
    223229
    224230protected:
    225 
    226     /* GUI thread locker: */
    227     void blockGUIthread()
    228     {
    229         m_fConditionDone = false;
    230         while (!m_fConditionDone)
    231         {
    232             /* Lock mutex initially: */
    233             m_mutex.lock();
    234             /* Perform idle-processing every 100ms,
    235              * and waiting for direct wake up signal: */
    236             m_condition.wait(&m_mutex, 100);
    237             /* Process queued signals posted to GUI thread: */
    238             qApp->processEvents();
    239             /* Unlock mutex finally: */
    240             m_mutex.unlock();
    241         }
    242         m_fAllowToDestroySerializer = true;
    243     }
    244231
    245232    /* Settings processor: */
     
    275262            /* Notify listeners about page was processed: */
    276263            emit sigNotifyAboutPageProcessed(pPage->id());
    277             /* Try to wake up GUI thread, but
    278              * it can be busy idle-processing for loaded pages: */
    279             if (!m_fConditionDone)
     264            /* If serializer saves settings => wake up GUI thread: */
     265            if (m_direction == UISettingsSerializeDirection_Save)
    280266                m_condition.wakeAll();
     267            /* Break further processing if page had failed: */
    281268            if (pPage->failed())
    282269                break;
     
    284271        /* Notify listeners about all pages were processed: */
    285272        emit sigNotifyAboutPagesProcessed();
    286         /* Try to wake up GUI thread, but
    287          * it can be busy idle-processing loaded pages: */
    288         if (!m_fConditionDone)
     273        /* If serializer saves settings => wake up GUI thread: */
     274        if (m_direction == UISettingsSerializeDirection_Save)
    289275            m_condition.wakeAll();
    290276    }
     
    294280    QVariant m_data;
    295281    UISettingsPageMap m_pages;
    296     bool m_fConditionDone;
     282    bool m_fSavingComplete;
    297283    bool m_fAllowToDestroySerializer;
    298     int m_iPageIdWeAreWaitingFor;
    299284    int m_iIdOfHighPriorityPage;
    300285    QMutex m_mutex;
     
    421406    /* Choose first item by default: */
    422407    m_pSelector->selectById(0);
     408}
     409
     410UISettingsDialogGlobal::~UISettingsDialogGlobal()
     411{
     412    /* Delete serializer early if exists: */
     413    if (UISettingsSerializer::instance())
     414        delete UISettingsSerializer::instance();
    423415}
    424416
     
    439431    /* Start loader: */
    440432    pGlobalSettingsLoader->start();
    441     /* Wait for just one (first) page to be loaded: */
    442     pGlobalSettingsLoader->waitForPageToBeProcessed(m_pSelector->currentId());
    443433}
    444434
     
    461451    /* Start saver: */
    462452    pGlobalSettingsSaver->start();
    463     /* Wait for all pages to be saved: */
    464     pGlobalSettingsSaver->waitForPagesToBeProcessed();
    465453
    466454    /* Get updated properties & settings: */
     
    737725}
    738726
     727UISettingsDialogMachine::~UISettingsDialogMachine()
     728{
     729    /* Delete serializer early if exists: */
     730    if (UISettingsSerializer::instance())
     731        delete UISettingsSerializer::instance();
     732}
     733
    739734void UISettingsDialogMachine::loadData()
    740735{
     
    774769    /* Start page loader: */
    775770    pMachineSettingsLoader->start();
    776     /* Wait for just one (required) page to be loaded: */
    777     pMachineSettingsLoader->waitForPageToBeProcessed(m_pSelector->currentId());
    778771}
    779772
     
    812805    /* Start saver: */
    813806    pMachineSettingsSaver->start();
    814     /* Wait for all pages to be saved: */
    815     pMachineSettingsSaver->waitForPagesToBeProcessed();
    816807
    817808    /* Get updated machine: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h

    r39779 r41042  
    4646
    4747    UISettingsDialogGlobal(QWidget *pParent);
     48    ~UISettingsDialogGlobal();
    4849
    4950protected:
     
    8687    UISettingsDialogMachine(QWidget *pParent, const QString &strMachineId,
    8788                            const QString &strCategory, const QString &strControl);
     89    ~UISettingsDialogMachine();
    8890
    8991protected:
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