Make getPaintDelayUsecs threadsafe

This commit is contained in:
Zach Pomerantz 2016-05-10 16:06:33 -07:00
parent 4711c23d9d
commit dd6a4dd091
2 changed files with 7 additions and 2 deletions

View file

@ -25,13 +25,17 @@ void DisplayPlugin::deactivate() {
} }
int64_t DisplayPlugin::getPaintDelayUsecs() const { int64_t DisplayPlugin::getPaintDelayUsecs() const {
std::lock_guard<std::mutex> lock(_paintDelayMutex);
return _paintDelayTimer.isValid() ? _paintDelayTimer.nsecsElapsed() / NSECS_PER_USEC : 0; return _paintDelayTimer.isValid() ? _paintDelayTimer.nsecsElapsed() / NSECS_PER_USEC : 0;
} }
void DisplayPlugin::incrementPresentCount() { void DisplayPlugin::incrementPresentCount() {
#ifdef DEBUG_PAINT_DELAY #ifdef DEBUG_PAINT_DELAY
// Avoid overhead if we are not debugging // Avoid overhead if we are not debugging
_paintDelayTimer.start(); {
std::lock_guard<std::mutex> lock(_paintDelayMutex);
_paintDelayTimer.start();
}
#endif #endif
++_presentedFrameIndex; ++_presentedFrameIndex;

View file

@ -161,7 +161,7 @@ public:
// Rate at which rendered frames are being skipped // Rate at which rendered frames are being skipped
virtual float droppedFrameRate() const { return -1.0f; } virtual float droppedFrameRate() const { return -1.0f; }
uint32_t presentCount() const { return _presentedFrameIndex; } uint32_t presentCount() const { return _presentedFrameIndex; }
// Time since last call to incrementPresentCount. Only valid if DEBUG_PAINT_DELAY is defined // Time since last call to incrementPresentCount (only valid if DEBUG_PAINT_DELAY is defined)
int64_t getPaintDelayUsecs() const; int64_t getPaintDelayUsecs() const;
virtual void cycleDebugOutput() {} virtual void cycleDebugOutput() {}
@ -176,6 +176,7 @@ protected:
private: private:
std::atomic<uint32_t> _presentedFrameIndex; std::atomic<uint32_t> _presentedFrameIndex;
mutable std::mutex _paintDelayMutex;
QElapsedTimer _paintDelayTimer; QElapsedTimer _paintDelayTimer;
}; };