Ensure invlid-syncs are handled in thread-sync 78/47578/2
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 4 Sep 2015 16:58:52 +0000 (17:58 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Sat, 5 Sep 2015 09:22:52 +0000 (10:22 +0100)
We can sometimes get an invalid-sync from the hardware.  We should ensure we do not wake the
update-thread if this is the case.

However, we could be shutting down while getting several invalid vsyncs so we still check that.

Change-Id: Ib6424cce5ee1bbf106764b27883968b64793a4f3

adaptors/base/thread-synchronization.cpp

index 933346e..50a1cbc 100644 (file)
@@ -532,50 +532,57 @@ bool ThreadSynchronization::VSyncReady( bool validSync, unsigned int frameNumber
 {
   LOG_VSYNC_TRACE;
 
+  // Ensure we do not process an invalid v-sync
+  if( validSync )
   {
-    ConditionalWait::ScopedLock vSyncLock( mVSyncThreadWaitCondition );
-    if( numberOfVSyncsPerRender != mNumberOfVSyncsPerRender )
     {
-      numberOfVSyncsPerRender = mNumberOfVSyncsPerRender; // save it back
-      mFrameTime.SetMinimumFrameTimeInterval( mNumberOfVSyncsPerRender * TIME_PER_FRAME_IN_MICROSECONDS );
-    }
+      ConditionalWait::ScopedLock vSyncLock( mVSyncThreadWaitCondition );
+      if( numberOfVSyncsPerRender != mNumberOfVSyncsPerRender )
+      {
+        numberOfVSyncsPerRender = mNumberOfVSyncsPerRender; // save it back
+        mFrameTime.SetMinimumFrameTimeInterval( mNumberOfVSyncsPerRender * TIME_PER_FRAME_IN_MICROSECONDS );
+      }
 
-    if( validSync )
-    {
       mFrameTime.SetSyncTime( frameNumber );
     }
-  }
 
-  if( ! mVSyncThreadInitialised )
-  {
-    LOG_VSYNC( "Initialised" );
+    if( ! mVSyncThreadInitialised )
+    {
+      LOG_VSYNC( "Initialised" );
 
-    mVSyncThreadInitialised = TRUE;
+      mVSyncThreadInitialised = TRUE;
 
-    // Notify event thread that this thread is up and running, this locks so we should have a scoped-lock
-    NotifyThreadInitialised();
-  }
-  else
-  {
-    // Increment v-sync-ahead-of-update count and inform update-thread
+      // Notify event thread that this thread is up and running, this locks so we should have a scoped-lock
+      NotifyThreadInitialised();
+    }
+    else
     {
-      ConditionalWait::ScopedLock lock( mUpdateThreadWaitCondition );
-      ++mVSyncAheadOfUpdate;
-      LOG_VSYNC_COUNTER_VSYNC( " vSyncAheadOfUpdate(%d)", mVSyncAheadOfUpdate );
+      // Increment v-sync-ahead-of-update count and inform update-thread
+      {
+        ConditionalWait::ScopedLock lock( mUpdateThreadWaitCondition );
+        ++mVSyncAheadOfUpdate;
+        LOG_VSYNC_COUNTER_VSYNC( " vSyncAheadOfUpdate(%d)", mVSyncAheadOfUpdate );
+      }
+      mUpdateThreadWaitCondition.Notify();
     }
-    mUpdateThreadWaitCondition.Notify();
-  }
 
-  // Ensure update-thread has set us to run before continuing
-  // Ensure we do not wait if we're supposed to stop
-  {
-    ConditionalWait::ScopedLock vSyncLock( mVSyncThreadWaitCondition );
-    while( ! mVSyncThreadRunning && ! mVSyncThreadStop )
+    // Ensure update-thread has set us to run before continuing
+    // Ensure we do not wait if we're supposed to stop
     {
-      LOG_VSYNC( "WAIT" );
-      mVSyncThreadWaitCondition.Wait( vSyncLock );
+      ConditionalWait::ScopedLock vSyncLock( mVSyncThreadWaitCondition );
+      while( ! mVSyncThreadRunning && ! mVSyncThreadStop )
+      {
+        LOG_VSYNC( "WAIT" );
+        mVSyncThreadWaitCondition.Wait( vSyncLock );
+      }
     }
   }
+  else
+  {
+    LOG_VSYNC( "INVALID SYNC" );
+
+    // Later we still check if the v-sync thread is supposed to keep running so we can still stop the thread if we are supposed to
+  }
 
   return IsVSyncThreadRunning(); // Call to this function locks so should not be called if we have a scoped-lock
 }