From: Adeel Kazmi Date: Fri, 4 Sep 2015 16:58:52 +0000 (+0100) Subject: Ensure invlid-syncs are handled in thread-sync X-Git-Tag: dali_1.1.2~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F78%2F47578%2F2;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Ensure invlid-syncs are handled in thread-sync 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 --- diff --git a/adaptors/base/thread-synchronization.cpp b/adaptors/base/thread-synchronization.cpp index 933346e..50a1cbc 100644 --- a/adaptors/base/thread-synchronization.cpp +++ b/adaptors/base/thread-synchronization.cpp @@ -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 }