22 #include "MCTimer.hpp" 28 #include "MCThreadLocalData.hpp" 30 #ifndef __AIBO_BUILD__ 31 #include <QElapsedTimer> 38 static SystemTime AiboTimer;
54 bool CheckStaticTimerVariables()
56 if (!SystemTimeStart.get())
58 SystemTimeStart.reset(
new int64_t);
60 HibernationTimeShift.reset(
new int64_t);
61 *HibernationTimeShift = 0;
62 HibernationStartTime.reset(
new int64_t);
63 *HibernationStartTime = 0;
72 Duration((int64_t)duration*(duration > 0 ? 1000 : 1)), LastShot(-1), Shots(-1),
85 SystemTimeHandler.reset(&handler);
87 CheckStaticTimerVariables();
94 int64_t CurrentTime = 0;
96 if (HibernationStartTime.get() && *HibernationStartTime > 0)
98 CurrentTime = *HibernationStartTime;
100 if (SystemTimeHandler.get())
102 CurrentTime = SystemTimeHandler->GetSystemTime();
105 #ifdef __AIBO_BUILD__ 106 GetSystemTime(&AiboTimer);
107 CurrentTime = (int64_t)AiboTimer.seconds*1000000+AiboTimer.useconds;
109 if (unlikely(!GlobalTimer.get()))
111 GlobalTimer.reset(
new QElapsedTimer);
112 GlobalTimer->start();
114 CurrentTime = (int64_t)GlobalTimer->nsecsElapsed() / 1000;
117 if (CheckStaticTimerVariables())
119 *SystemTimeStart = CurrentTime;
122 return relative_time ? CurrentTime-*SystemTimeStart-*HibernationTimeShift : CurrentTime-*HibernationTimeShift;
128 CheckStaticTimerVariables();
135 CheckStaticTimerVariables();
136 if (HibernationTimer->IsStarted())
139 HibernationTimer->Start();
148 CheckStaticTimerVariables();
149 if (!HibernationTimer->IsStarted())
153 *HibernationStartTime = 0;
154 *HibernationTimeShift += HibernationTimer->GetElapsedTimeInUSecs();
155 HibernationTimer->Stop();
161 Duration = (int64_t)duration*(duration > 0 ? 1000 : 1);
void Start(int time_shift=0)
Start the timer.
virtual int64_t GetSystemTime()=0
Get system time.
void Reset()
Reset the timer.
void StartFromTime(int start_time)
Start from a given time.
bool IsStarted() const
Check if the timer has been started.
void Stop()
Stop the timer.
int64_t LastShot
The last shot in microseconds.
int GetStartTime() const
Get the start time.
static void ResumeSystemTime()
Hibernate the system time.
MC::TimerType TimerType
The type of the timer.
int GetDuration() const
Get the duration of the time.
void SetDuration(int duration)
Set the duration of the timer.
int64_t Duration
Duration.
int GetElapsedTime()
Get the elapsed time since the timer has been started or since the last timeout.
MCTimer(MC::TimerType timer_type=MC::SingleShot, int duration=-1)
Constructs a given type of the timer varying the expiration and the shot method.
static int64_t GetElapsedSystemTime(bool relative_time=true)
Get the system time.
int64_t StartTime
Start time.
static void ResetElapsedSystemTime()
Reset the system time measurement.
Simple timer class with microsecond precision.
int64_t GetElapsedTimeInUSecs()
Get the elapsed time in microseconds since the timer has been started or since the last timeout...
static void HibernateSystemTime()
Hibernate the system time.
static void SetCustomHandler(MASystemTimeHandler &handler)
Set system time handler.
A wrapper class to cover boost::thread_specific_ptr/folly::ThreadLocal API on certain targets...
bool Timeout()
Check if the timer has been timed out.