Changeset 33666 in vbox
- Timestamp:
- Nov 1, 2010 7:21:19 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 67286
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp
r33639 r33666 21 21 #include <QStackedWidget> 22 22 #include <QThread> 23 #include <QTimer> 23 #include <QMutex> 24 #include <QWaitCondition> 24 25 25 26 /* Local includes */ … … 77 78 , m_direction(direction) 78 79 , m_data(data) 80 , m_fConditionDone(false) 79 81 , m_iPageIdWeAreWaitingFor(-1) 80 82 , m_iIdOfHighPriorityPage(-1) … … 83 85 connect(this, SIGNAL(sigNotifyAboutPageProcessed(int)), this, SLOT(sltHandleProcessedPage(int)), Qt::QueuedConnection); 84 86 connect(this, SIGNAL(sigNotifyAboutPagesProcessed()), this, SLOT(sltHandleProcessedPages()), Qt::QueuedConnection); 85 connect(this, SIGNAL(finished()), this, SLOT( sltDestroySerializer()), Qt::QueuedConnection);87 connect(this, SIGNAL(finished()), this, SLOT(deleteLater()), Qt::QueuedConnection); 86 88 87 89 /* Set instance: */ … … 100 102 if (isRunning()) 101 103 wait(); 102 103 /* If serializer still having event loop running,104 * we should quit it now: */105 if (m_eventLoop.isRunning())106 {107 m_eventLoop.processEvents();108 m_eventLoop.quit();109 }110 104 } 111 105 … … 123 117 void waitForPageToBeProcessed(int iPageId) 124 118 { 125 if (!isRunning())126 return;127 119 m_iPageIdWeAreWaitingFor = iPageId; 128 m_eventLoop.exec();120 blockGUIthread(); 129 121 } 130 122 … … 132 124 void waitForPagesToBeProcessed() 133 125 { 134 if (!isRunning())135 return;136 126 m_iPageIdWeAreWaitingFor = -1; 137 m_eventLoop.exec();127 blockGUIthread(); 138 128 } 139 129 … … 192 182 m_pages[iPageId]->getFromCache(); 193 183 } 194 /* If thats the page we are waiting for, unlock the loop, 195 * after all the events of the page which is currently fetching 196 * from cache will be processed: */ 197 if (iPageId == m_iPageIdWeAreWaitingFor && m_eventLoop.isRunning()) 198 QTimer::singleShot(0, this, SLOT(sltStopEventLoop())); 184 /* If thats the page we are waiting for, 185 * we should flag GUI thread to unlock itself: */ 186 if (iPageId == m_iPageIdWeAreWaitingFor && !m_fConditionDone) 187 m_fConditionDone = true; 199 188 } 200 189 … … 202 191 void sltHandleProcessedPages() 203 192 { 204 /* If all the pages were processed, unlock the loop, 205 * after all the events of the last page will be processed: */ 206 if (m_eventLoop.isRunning()) 207 QTimer::singleShot(0, this, SLOT(sltStopEventLoop())); 208 } 209 210 /* Slot to destroy serializer: */ 211 void sltDestroySerializer() 212 { 213 /* If event loop is still running, 214 * we should try to destroy serializer only on next iteration: */ 215 if (m_eventLoop.isRunning()) 216 QTimer::singleShot(0, this, SLOT(sltDestroySerializer())); 217 /* Else really make a request to destroy serializer: */ 218 else 219 deleteLater(); 220 } 221 222 /* Slot to stop event loop: */ 223 void sltStopEventLoop() 224 { 225 /* If event loop is still running, we should stop it: */ 226 if (m_eventLoop.isRunning()) 227 { 228 m_eventLoop.processEvents(); 229 m_eventLoop.quit(); 230 m_eventLoop.processEvents(); 231 } 193 /* We should flag GUI thread to unlock itself: */ 194 if (!m_fConditionDone) 195 m_fConditionDone = true; 232 196 } 233 197 234 198 protected: 199 200 /* GUI thread locker: */ 201 void blockGUIthread() 202 { 203 m_fConditionDone = false; 204 while (!m_fConditionDone) 205 { 206 /* Lock mutex initially: */ 207 m_mutex.lock(); 208 /* Perform idle-processing every 100ms, 209 * and waiting for direct wake up signal: */ 210 m_condition.wait(&m_mutex, 100); 211 /* Process queued signals posted to GUI thread: */ 212 qApp->processEvents(); 213 /* Unlock mutex finally: */ 214 m_mutex.unlock(); 215 } 216 } 235 217 236 218 /* Settings processor: */ … … 257 239 /* Remember what page was processed: */ 258 240 pPage->setProcessed(true); 241 /* Remove processed page from our map: */ 242 pages.remove(pPage->id()); 259 243 /* Notify listeners about page was processed: */ 260 244 emit sigNotifyAboutPageProcessed(pPage->id()); 261 /* Remove processed page from our map: */ 262 pages.remove(pPage->id()); 245 /* Try to wake up GUI thread, but 246 * it can be busy idle-processing for loaded pages: */ 247 if (!m_fConditionDone) 248 m_condition.wakeAll(); 263 249 } 264 250 /* Notify listeners about all pages were processed: */ 265 251 emit sigNotifyAboutPagesProcessed(); 252 /* Try to wake up GUI thread, but 253 * it can be busy idle-processing loaded pages: */ 254 if (!m_fConditionDone) 255 m_condition.wakeAll(); 266 256 } 267 257 … … 269 259 UISettingsSerializeDirection m_direction; 270 260 QVariant m_data; 271 QEventLoop m_eventLoop;272 261 UISettingsPageMap m_pages; 262 bool m_fConditionDone; 273 263 int m_iPageIdWeAreWaitingFor; 274 264 int m_iIdOfHighPriorityPage; 265 QMutex m_mutex; 266 QWaitCondition m_condition; 275 267 static UISettingsSerializer *m_pInstance; 276 268 };
Note:
See TracChangeset
for help on using the changeset viewer.