mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:37:58 +02:00
Use atomic<bool> and compare_exchange_strong
This commit is contained in:
parent
a2a6cd0c7a
commit
67d43b4fac
2 changed files with 8 additions and 9 deletions
|
@ -275,7 +275,7 @@ private:
|
||||||
switch ((int)event->type()) {
|
switch ((int)event->type()) {
|
||||||
case ApplicationEvent::Render:
|
case ApplicationEvent::Render:
|
||||||
render();
|
render();
|
||||||
qApp->_pendingRenderEventCount--;
|
qApp->_pendingRenderEvent.store(false);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -2723,13 +2723,12 @@ bool Application::importFromZIP(const QString& filePath) {
|
||||||
|
|
||||||
// thread-safe
|
// thread-safe
|
||||||
void Application::onPresent(quint32 frameCount) {
|
void Application::onPresent(quint32 frameCount) {
|
||||||
if (_pendingIdleEventCount.load() == 0) {
|
bool expected = false;
|
||||||
_pendingIdleEventCount++;
|
if (_pendingIdleEvent.compare_exchange_strong(expected, true)) {
|
||||||
postEvent(this, new QEvent((QEvent::Type)ApplicationEvent::Idle), Qt::HighEventPriority);
|
postEvent(this, new QEvent((QEvent::Type)ApplicationEvent::Idle), Qt::HighEventPriority);
|
||||||
}
|
}
|
||||||
|
expected = false;
|
||||||
if (_renderEventHandler && !isAboutToQuit() && _pendingRenderEventCount.load() == 0) {
|
if (_renderEventHandler && !isAboutToQuit() && _pendingRenderEvent.compare_exchange_strong(expected, true)) {
|
||||||
_pendingRenderEventCount++;
|
|
||||||
postEvent(_renderEventHandler, new QEvent((QEvent::Type)ApplicationEvent::Render));
|
postEvent(_renderEventHandler, new QEvent((QEvent::Type)ApplicationEvent::Render));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2845,7 +2844,7 @@ bool Application::event(QEvent* event) {
|
||||||
}
|
}
|
||||||
#endif // DEBUG_EVENT_QUEUE
|
#endif // DEBUG_EVENT_QUEUE
|
||||||
|
|
||||||
_pendingIdleEventCount--;
|
_pendingIdleEvent.store(false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -718,7 +718,7 @@ private:
|
||||||
|
|
||||||
friend class RenderEventHandler;
|
friend class RenderEventHandler;
|
||||||
|
|
||||||
std::atomic<int> _pendingIdleEventCount { 0 };
|
std::atomic<bool> _pendingIdleEvent { false };
|
||||||
std::atomic<int> _pendingRenderEventCount { 0 };
|
std::atomic<bool> _pendingRenderEvent { false };
|
||||||
};
|
};
|
||||||
#endif // hifi_Application_h
|
#endif // hifi_Application_h
|
||||||
|
|
Loading…
Reference in a new issue