From 9a878f148492cd20ea41a4111848bebaa71ff0e9 Mon Sep 17 00:00:00 2001 From: Richard Underhill Date: Fri, 4 Sep 2015 13:35:49 +0100 Subject: [PATCH] Fix for thread contention issues in FrameTime object. Change-Id: I356df48263002c0794f5604a1607c0d8788df0a1 Signed-off-by: Richard Underhill --- adaptors/base/frame-time.cpp | 3 +++ adaptors/base/frame-time.h | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/adaptors/base/frame-time.cpp b/adaptors/base/frame-time.cpp index 025a6a7..c8031a6 100644 --- a/adaptors/base/frame-time.cpp +++ b/adaptors/base/frame-time.cpp @@ -88,6 +88,7 @@ void FrameTime::SetMinimumFrameTimeInterval( unsigned int interval ) void FrameTime::SetSyncTime( unsigned int frameNumber ) { + Dali::Mutex::ScopedLock lock( mMutex ); // Only set the render time if we are running if ( mRunning ) { @@ -101,6 +102,7 @@ void FrameTime::SetSyncTime( unsigned int frameNumber ) void FrameTime::Suspend() { + Dali::Mutex::ScopedLock lock( mMutex ); mRunning = FALSE; // Reset members @@ -148,6 +150,7 @@ void FrameTime::WakeUp() void FrameTime::PredictNextSyncTime( float& lastFrameDeltaSeconds, unsigned int& lastSyncTimeMilliseconds, unsigned int& nextSyncTimeMilliseconds ) { + Dali::Mutex::ScopedLock lock( mMutex ); if ( mRunning ) { const unsigned int minimumFrameTimeInterval( mMinimumFrameTimeInterval ); diff --git a/adaptors/base/frame-time.h b/adaptors/base/frame-time.h index 42bc596..c3cb363 100644 --- a/adaptors/base/frame-time.h +++ b/adaptors/base/frame-time.h @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include namespace Dali { @@ -118,20 +119,21 @@ private: unsigned int mMinimumFrameTimeInterval; ///< The minimum frame time interval, set by Adaptor. - uint64_t mLastSyncTime; ///< The last Sync time (in microseconds). - uint64_t mLastSyncTimeAtUpdate; ///< The last Sync time at Update (in microseconds). + volatile uint64_t mLastSyncTime; ///< The last Sync time (in microseconds). + volatile uint64_t mLastSyncTimeAtUpdate; ///< The last Sync time at Update (in microseconds). unsigned int mLastSyncFrameNumber; ///< The last Sync frame number unsigned int mLastUpdateFrameNumber; ///< The last Sync frame number handled in Update. // NOTE cannot use bitfields or booleans as these are used from multiple threads, must use variable with machine word size for atomic read/write - unsigned int mRunning; ///< The state of the FrameTime object. + volatile unsigned int mRunning; ///< The state of the FrameTime object. unsigned int mFirstFrame; ///< Whether the current update is the first frame (after initialisation, resume or wake up). unsigned int mPreviousUpdateFrames[3]; ///< Array holding the number of frames Update took in the last three iterations. unsigned int writePos; ///< The current write position in the array. unsigned int mExtraUpdatesSinceSync; ///< The number of extra updates since the last Sync. + Dali::Mutex mMutex; ///< Mutex to ensure correct access locking. }; } // namespace Adaptor -- 2.7.4