make frametime state flags properly atomic read/write 45/28945/1
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Fri, 17 Oct 2014 10:15:44 +0000 (11:15 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Fri, 17 Oct 2014 10:18:33 +0000 (11:18 +0100)
Change-Id: I8b3f1680c6ef88e52cc6598904afc21e42b2b942

adaptors/base/frame-time.cpp
adaptors/base/frame-time.h

index 6c08241..b31b6df 100644 (file)
@@ -46,6 +46,10 @@ const unsigned int MICROSECONDS_PER_MILLISECOND( 1000u );
 const float        MICROSECONDS_TO_SECONDS( 0.000001f );
 
 const unsigned int HISTORY_SIZE(3);
+
+// constants to keep code readability with unsigned int has to be used as boolean (due to multithreading)
+const unsigned int TRUE = 1u;
+const unsigned int FALSE = 0u;
 } // unnamed namespace
 
 
@@ -56,8 +60,8 @@ FrameTime::FrameTime( PlatformAbstraction& platform )
   mLastSyncTimeAtUpdate( 0u ),
   mLastSyncFrameNumber( 0u ),
   mLastUpdateFrameNumber( 0u ),
-  mRunning( true ),
-  mFirstFrame( true ),
+  mRunning( TRUE ),
+  mFirstFrame( TRUE ),
   writePos( 0u ),
   mExtraUpdatesSinceSync( 0u )
 {
@@ -97,7 +101,7 @@ void FrameTime::SetSyncTime( unsigned int frameNumber )
 
 void FrameTime::Suspend()
 {
-  mRunning = false;
+  mRunning = FALSE;
 
   // Reset members
   mLastSyncFrameNumber = 0;
@@ -119,9 +123,9 @@ void FrameTime::Resume()
   DALI_LOG_INFO( gLogFilter, Debug::Concise, "FrameTime: Resuming\n" );
 
   SetLastSyncTime();   // Should only update the last Sync time so the elapsed time during suspension is taken into consideration when we next update.
-  mFirstFrame = true;
+  mFirstFrame = TRUE;
 
-  mRunning = true;
+  mRunning = TRUE;
 }
 
 void FrameTime::Sleep()
@@ -138,8 +142,8 @@ void FrameTime::WakeUp()
 
   SetLastSyncTime();
   mLastSyncTimeAtUpdate = mLastSyncTime; // We do not want any animations to progress as we have just been woken up.
-  mFirstFrame = true;
-  mRunning = true;
+  mFirstFrame = TRUE;
+  mRunning = TRUE;
 }
 
 void FrameTime::PredictNextSyncTime( float& lastFrameDeltaSeconds, unsigned int& lastSyncTimeMilliseconds, unsigned int& nextSyncTimeMilliseconds )
@@ -199,7 +203,7 @@ void FrameTime::PredictNextSyncTime( float& lastFrameDeltaSeconds, unsigned int&
 
     mLastUpdateFrameNumber = lastSyncFrameNumber;
     mLastSyncTimeAtUpdate = lastSyncTime;
-    mFirstFrame = false;
+    mFirstFrame = FALSE;
 
     // Calculate the time till the next render
     unsigned int timeTillNextRender( minimumFrameTimeInterval * framesTillNextSync );
index 06881d8..3bc133a 100644 (file)
@@ -113,23 +113,24 @@ private:
 
 private:
 
-  Integration::PlatformAbstraction& mPlatform;    ///< The platform abstraction.
+  Integration::PlatformAbstraction& mPlatform; ///< The platform abstraction.
 
-  unsigned int mMinimumFrameTimeInterval;   ///< The minimum frame time interval, set by Adaptor.
+  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).
+  uint64_t mLastSyncTime;                ///< The last Sync time (in microseconds).
+  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.
+  unsigned int mLastSyncFrameNumber;     ///< The last Sync frame number
+  unsigned int mLastUpdateFrameNumber;   ///< The last Sync frame number handled in Update.
 
-  bool         mRunning:1;                  ///< The state of the FrameTime object.
-  bool         mFirstFrame:1;               ///< Whether the current update is the first frame (after initialisation, resume or wake up).
+  // 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.
+  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 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.
+  unsigned int mExtraUpdatesSinceSync;   ///< The number of extra updates since the last Sync.
 };
 
 } // namespace Adaptor