@@ -1918,21 +1918,26 @@ void PMTraceConsumer::AddPresentToCompletedList(std::shared_ptr<PresentEvent> co
19181918 }
19191919
19201920 UpdateReadyCount (present);
1921-
1922- // It's possible for a deferred condition to never be cleared. e.g., a process' last present
1923- // doesn't get a Present_Stop event. When this happens the deferred present will prevent all
1924- // subsequent presents from other processes from being dequeued until the ring buffer wraps and
1925- // forces it out, which is likely longer than we want to wait. So we check here if there is
1926- // a stuck deferred present and clear the deferral if it gets too old.
1927- if (mReadyCount == 0 ) {
1928- auto const & deferredPresent = mCompletedPresents [mCompletedIndex ];
1929- if (present->PresentStartTime >= deferredPresent->PresentStartTime &&
1930- present->PresentStartTime - deferredPresent->PresentStartTime > mDeferralTimeLimit ) {
1931- VerboseTraceBeforeModifyingPresent (deferredPresent.get ());
1932- deferredPresent->IsLost = true ;
1933- deferredPresent->WaitingForPresentStop = false ;
1934- deferredPresent->WaitingForFlipFrameType = false ;
1935- UpdateReadyCount (deferredPresent);
1921+
1922+ {
1923+ std::unique_lock<std::mutex> lock (mPresentEventMutex );
1924+ // It's possible for a deferred condition to never be cleared. e.g., a process' last present
1925+ // doesn't get a Present_Stop event. When this happens the deferred present will prevent all
1926+ // subsequent presents from other processes from being dequeued until the ring buffer wraps and
1927+ // forces it out, which is likely longer than we want to wait. So we check here if there is
1928+ // a stuck deferred present and clear the deferral if it gets too old.
1929+ if (mReadyCount == 0 ) {
1930+ auto const & deferredPresent = mCompletedPresents [mCompletedIndex ];
1931+ if (present->PresentStartTime >= deferredPresent->PresentStartTime &&
1932+ present->PresentStartTime - deferredPresent->PresentStartTime > mDeferralTimeLimit ) {
1933+ VerboseTraceBeforeModifyingPresent (deferredPresent.get ());
1934+ deferredPresent->IsLost = true ;
1935+ deferredPresent->WaitingForPresentStop = false ;
1936+ deferredPresent->WaitingForFlipFrameType = false ;
1937+ // UpdateReadyCount also locks the mPresentEventMutex so unlock here
1938+ lock.unlock ();
1939+ UpdateReadyCount (deferredPresent);
1940+ }
19361941 }
19371942 }
19381943}
@@ -2379,9 +2384,10 @@ void PMTraceConsumer::DequeueProcessEvents(std::vector<ProcessEvent>& outProcess
23792384void PMTraceConsumer::DequeuePresentEvents (std::vector<std::shared_ptr<PresentEvent>>& outPresentEvents)
23802385{
23812386 outPresentEvents.clear ();
2382- if (mReadyCount > 0 ) {
2383- std::lock_guard<std::mutex> lock (mPresentEventMutex );
23842387
2388+ std::lock_guard<std::mutex> lock (mPresentEventMutex );
2389+
2390+ if (mReadyCount > 0 ) {
23852391 outPresentEvents.resize (mReadyCount , nullptr );
23862392 for (uint32_t i = 0 ; i < mReadyCount ; ++i) {
23872393 std::swap (outPresentEvents[i], mCompletedPresents [mCompletedIndex ]);
0 commit comments