- Timestamp:
- Apr 24, 2012 10:39:09 AM (13 years ago)
- 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 74 74 Q_OBJECT; 75 75 76 signals: 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 76 87 public: 77 88 … … 84 95 , m_direction(direction) 85 96 , 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) 89 99 , m_iIdOfHighPriorityPage(-1) 90 100 { 101 /* Set instance: */ 102 m_pInstance = this; 103 91 104 /* Connecting this signals: */ 92 105 connect(this, SIGNAL(sigNotifyAboutPageProcessed(int)), this, SLOT(sltHandleProcessedPage(int)), Qt::QueuedConnection); … … 96 109 connect(this, SIGNAL(sigNotifyAboutProcessStarted()), parent(), SLOT(sltHandleProcessStarted()), Qt::QueuedConnection); 97 110 connect(this, SIGNAL(sigNotifyAboutPageProcessed(int)), parent(), SLOT(sltHandlePageProcessed()), Qt::QueuedConnection); 98 99 /* Set instance: */100 m_pInstance = this;101 111 } 102 112 … … 104 114 ~UISettingsSerializer() 105 115 { 106 /* Reset instance: */107 m_pInstance = 0;108 109 116 /* If serializer is being destructed by it's parent, 110 117 * thread could still be running, we have to wait … … 112 119 if (isRunning()) 113 120 wait(); 121 122 /* Clear instance: */ 123 m_pInstance = 0; 114 124 } 115 125 … … 124 134 } 125 135 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 140 136 /* Raise priority of page: */ 141 137 void raisePriorityOfPage(int iPageId) … … 157 153 QVariant& data() { return m_data; } 158 154 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 170 155 public slots: 171 156 172 157 void start(Priority priority = InheritPriority) 173 158 { 174 /* Notify listeners a 159 /* Notify listeners about we are starting: */ 175 160 emit sigNotifyAboutProcessStarted(); 161 176 162 /* If serializer saves settings: */ 177 163 if (m_direction == UISettingsSerializeDirection_Save) … … 181 167 m_pages.values()[iPageIndex]->putToCache(); 182 168 } 183 /* Start async thread: */ 169 170 /* Start async serializing thread: */ 184 171 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 } 185 191 } 186 192 … … 197 203 m_pages[iPageId]->getFromCache(); 198 204 } 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: */ 206 208 void sltHandleProcessedPages() 207 209 { 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 } 211 217 } 212 218 … … 223 229 224 230 protected: 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 }244 231 245 232 /* Settings processor: */ … … 275 262 /* Notify listeners about page was processed: */ 276 263 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) 280 266 m_condition.wakeAll(); 267 /* Break further processing if page had failed: */ 281 268 if (pPage->failed()) 282 269 break; … … 284 271 /* Notify listeners about all pages were processed: */ 285 272 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) 289 275 m_condition.wakeAll(); 290 276 } … … 294 280 QVariant m_data; 295 281 UISettingsPageMap m_pages; 296 bool m_f ConditionDone;282 bool m_fSavingComplete; 297 283 bool m_fAllowToDestroySerializer; 298 int m_iPageIdWeAreWaitingFor;299 284 int m_iIdOfHighPriorityPage; 300 285 QMutex m_mutex; … … 421 406 /* Choose first item by default: */ 422 407 m_pSelector->selectById(0); 408 } 409 410 UISettingsDialogGlobal::~UISettingsDialogGlobal() 411 { 412 /* Delete serializer early if exists: */ 413 if (UISettingsSerializer::instance()) 414 delete UISettingsSerializer::instance(); 423 415 } 424 416 … … 439 431 /* Start loader: */ 440 432 pGlobalSettingsLoader->start(); 441 /* Wait for just one (first) page to be loaded: */442 pGlobalSettingsLoader->waitForPageToBeProcessed(m_pSelector->currentId());443 433 } 444 434 … … 461 451 /* Start saver: */ 462 452 pGlobalSettingsSaver->start(); 463 /* Wait for all pages to be saved: */464 pGlobalSettingsSaver->waitForPagesToBeProcessed();465 453 466 454 /* Get updated properties & settings: */ … … 737 725 } 738 726 727 UISettingsDialogMachine::~UISettingsDialogMachine() 728 { 729 /* Delete serializer early if exists: */ 730 if (UISettingsSerializer::instance()) 731 delete UISettingsSerializer::instance(); 732 } 733 739 734 void UISettingsDialogMachine::loadData() 740 735 { … … 774 769 /* Start page loader: */ 775 770 pMachineSettingsLoader->start(); 776 /* Wait for just one (required) page to be loaded: */777 pMachineSettingsLoader->waitForPageToBeProcessed(m_pSelector->currentId());778 771 } 779 772 … … 812 805 /* Start saver: */ 813 806 pMachineSettingsSaver->start(); 814 /* Wait for all pages to be saved: */815 pMachineSettingsSaver->waitForPagesToBeProcessed();816 807 817 808 /* Get updated machine: */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h
r39779 r41042 46 46 47 47 UISettingsDialogGlobal(QWidget *pParent); 48 ~UISettingsDialogGlobal(); 48 49 49 50 protected: … … 86 87 UISettingsDialogMachine(QWidget *pParent, const QString &strMachineId, 87 88 const QString &strCategory, const QString &strControl); 89 ~UISettingsDialogMachine(); 88 90 89 91 protected:
Note:
See TracChangeset
for help on using the changeset viewer.