* Platform independent.
* Add GetMilliseconds() to be used in the SceneHolder implementation.
Change-Id: I26977721d0f368e46c8519801957b69ad7d67eb0
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
#include <dali/internal/graphics/gles/egl-graphics.h>
#include <dali/internal/input/common/key-impl.h>
#include <dali/internal/input/common/physical-keyboard-impl.h>
+#include <dali/internal/system/common/time-service.h>
namespace Dali
{
#if defined(DEBUG_ENABLED)
Debug::Filter* gSceneHolderLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_SCENE_HOLDER");
#endif
-
-// Copied from x server
-static uint32_t GetCurrentMilliSeconds(void)
-{
- struct timeval tv;
-
- struct timespec tp;
- static clockid_t clockid;
-
- if(!clockid)
- {
-#ifdef CLOCK_MONOTONIC_COARSE
- if(clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
- (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
- {
- clockid = CLOCK_MONOTONIC_COARSE;
- }
- else
-#endif
- if(clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
- {
- clockid = CLOCK_MONOTONIC;
- }
- else
- {
- clockid = ~0L;
- }
- }
- if(clockid != ~0L && clock_gettime(clockid, &tp) == 0)
- {
- return static_cast<uint32_t>((tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L));
- }
-
- gettimeofday(&tv, NULL);
- return static_cast<uint32_t>((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
-}
-
} // unnamed namespace
uint32_t SceneHolder::mSceneHolderCounter = 0;
{
if(timeStamp < 1)
{
- timeStamp = GetCurrentMilliSeconds();
+ timeStamp = TimeService::GetMilliSeconds();
}
RecalculateTouchPosition(point);
#include <dali/internal/system/common/time-service.h>
// EXTERNAL INCLUDES
-#include <ctime>
+#include <chrono>
+#include <thread>
namespace Dali
{
namespace TimeService
{
-namespace
+void GetNanoseconds( uint64_t& timeInNanoseconds )
{
-const uint64_t NANOSECONDS_PER_SECOND = 1e+9;
+ // Get the time of a monotonic clock since its epoch.
+ auto epoch = std::chrono::steady_clock::now().time_since_epoch();
+
+ auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(epoch);
+
+ timeInNanoseconds = static_cast<uint64_t>(duration.count());
}
-void GetNanoseconds( uint64_t& timeInNanoseconds )
+uint32_t GetMilliSeconds()
{
- timespec timeSpec;
- if( clock_gettime( CLOCK_MONOTONIC, &timeSpec ) == 0 )
- {
- // Convert all values to uint64_t to match our return type
- timeInNanoseconds = ( static_cast< uint64_t >( timeSpec.tv_sec ) * NANOSECONDS_PER_SECOND ) + static_cast< uint64_t >( timeSpec.tv_nsec );
- }
- else
- {
- timeInNanoseconds = 0;
- }
+ // Get the time of a monotonic clock since its epoch.
+ auto epoch = std::chrono::steady_clock::now().time_since_epoch();
+
+ auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
+
+ return static_cast<uint32_t>(duration.count());
}
+
void SleepUntil( uint64_t timeInNanoseconds )
{
- timespec timeSpec;
- timeSpec.tv_sec = timeInNanoseconds / NANOSECONDS_PER_SECOND;
- timeSpec.tv_nsec = timeInNanoseconds % NANOSECONDS_PER_SECOND;
-
- // clock_nanosleep returns 0 if it sleeps for the period specified, otherwise it returns an error value
- // If an error value is returned, just sleep again till the absolute time specified
- while( clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &timeSpec, NULL ) )
- {
- }
+ using Clock = std::chrono::steady_clock;
+ using TimePoint = std::chrono::time_point<Clock>;
+
+ const Clock::duration duration = std::chrono::nanoseconds(timeInNanoseconds);
+ const TimePoint timePoint(duration);
+
+ std::this_thread::sleep_until(timePoint);
}
} // namespace TimeService
{
/**
- * @brief Get the monotonic time since some unspecified starting point (usually the boot time).
+ * @brief Get the monotonic time since the clock's epoch.
*
* @param[out] timeInNanoseconds The time in nanoseconds since the reference point.
*
void GetNanoseconds( uint64_t& timeInNanoseconds );
/**
- * @brief Sleeps until the monotonic time specified since some unspecified starting point (usually the boot time).
+ * @brief Get the monotonic time since the clock's epoch.
+ *
+ * @return The time in milliseconds since the reference point.
+ *
+ * @note The maximum value that can be returned is 0xFFFFFFFF which is 4,294,967,295. Therefore, this can overflow after approximately 49 days.
+ */
+uint32_t GetMilliSeconds();
+
+/**
+ * @brief Sleeps until the monotonic time specified since the clock's epoch.
*
* If the time specified has already passed, then it returns immediately.
*