Nugget
chrono.h
1 // Copyright (c) Electronic Arts Inc. All rights reserved.
4 
5 
7 // This file implements the eastl::chrono specification which is part of the
8 // standard STL date and time library. eastl::chrono implements all the
9 // mechanisms required to capture and manipulate times retrieved from the
10 // provided clocks. It implements the all of the features to allow type safe
11 // durations to be used in code.
13 
14 
15 #ifndef EASTL_CHRONO_H
16 #define EASTL_CHRONO_H
17 
18 #if defined(EA_PRAGMA_ONCE_SUPPORTED)
19  #pragma once
20 #endif
21 
22 #include <EASTL/internal/config.h>
23 #include <EASTL/type_traits.h>
24 #include <EASTL/numeric_limits.h>
25 #include <EASTL/ratio.h>
26 
27 
28 // TODO: move to platform specific cpp or header file
29 #if defined EA_PLATFORM_MICROSOFT
30  EA_DISABLE_ALL_VC_WARNINGS()
31 
32  #ifndef WIN32_LEAN_AND_MEAN
33  #define WIN32_LEAN_AND_MEAN
34  #endif
35 
36  #undef NOMINMAX
37  #define NOMINMAX
38 
39  #include <Windows.h>
40 
41  #ifdef min
42  #undef min
43  #endif
44  #ifdef max
45  #undef max
46  #endif
47 
48  EA_RESTORE_ALL_VC_WARNINGS()
49 #endif
50 
51 #if defined(EA_PLATFORM_MICROSOFT) && !defined(EA_PLATFORM_MINGW)
52  // Nothing to do
53 #elif defined(EA_PLATFORM_SONY)
54  #include <Dinkum/threads/xtimec.h>
55  #include <kernel.h>
56 #elif defined(EA_PLATFORM_APPLE)
57  #include <mach/mach_time.h>
58 #elif defined(EA_PLATFORM_POSIX) || defined(EA_PLATFORM_MINGW) || defined(EA_PLATFORM_ANDROID)
59  // Posix means Linux, Unix, and Macintosh OSX, among others (including Linux-based mobile platforms).
60  #if defined(EA_PLATFORM_MINGW)
61  #include <pthread_time.h>
62  #endif
63  #include <time.h>
64  #if (defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC))
65  #include <errno.h>
66  #else
67  #include <sys/time.h>
68  #include <unistd.h>
69  #endif
70 #endif
71 
72 
73 namespace eastl
74 {
75 namespace chrono
76 {
78  // treat_as_floating_point
80  template <class Rep>
82 
83 
85  // 20.12.4, duration_values
87  template <class Rep>
89  {
90  public:
91  EASTL_FORCE_INLINE static EA_CONSTEXPR Rep zero() { return Rep(0); }
92  EASTL_FORCE_INLINE static EA_CONSTEXPR Rep max() { return eastl::numeric_limits<Rep>::max(); }
93  EASTL_FORCE_INLINE static EA_CONSTEXPR Rep min() { return eastl::numeric_limits<Rep>::lowest(); }
94  };
95 
96 
98  // duration fwd_decl
100  template <typename Rep, typename Period = ratio<1>>
101  class duration;
102 
103 
104  namespace Internal
105  {
107  // IsRatio
109  template <typename> struct IsRatio : eastl::false_type {};
110  template <intmax_t N, intmax_t D> struct IsRatio<ratio<N, D>> : eastl::true_type {};
111  template <intmax_t N, intmax_t D> struct IsRatio<const ratio<N, D>> : eastl::true_type {};
112  template <intmax_t N, intmax_t D> struct IsRatio<volatile ratio<N, D>> : eastl::true_type {};
113  template <intmax_t N, intmax_t D> struct IsRatio<const volatile ratio<N, D>> : eastl::true_type {};
114 
115 
117  // IsDuration
119  template<typename> struct IsDuration : eastl::false_type{};
120  template<typename Rep, typename Period> struct IsDuration<duration<Rep, Period>> : eastl::true_type{};
121  template<typename Rep, typename Period> struct IsDuration<const duration<Rep, Period>> : eastl::true_type{};
122  template<typename Rep, typename Period> struct IsDuration<volatile duration<Rep, Period>> : eastl::true_type{};
123  template<typename Rep, typename Period> struct IsDuration<const volatile duration<Rep, Period>> : eastl::true_type{};
124 
125 
127  // RatioGCD
129  template <class Period1, class Period2>
130  struct RatioGCD
131  {
132  static_assert(IsRatio<Period1>::value, "Period1 is not a eastl::ratio type");
133  static_assert(IsRatio<Period2>::value, "Period2 is not a eastl::ratio type");
134 
137  };
138  };
139 
140 
142  // 20.12.5.7, duration_cast
144  namespace Internal
145  {
146  template <typename FromDuration,
147  typename ToDuration,
148  typename CommonPeriod =
149  typename ratio_divide<typename FromDuration::period, typename ToDuration::period>::type,
150  typename CommonRep = typename eastl::decay<typename eastl::common_type<typename ToDuration::rep,
151  typename FromDuration::rep,
152  intmax_t>::type>::type,
153  bool = CommonPeriod::num == 1,
154  bool = CommonPeriod::den == 1>
156 
157  template <typename FromDuration, typename ToDuration, typename CommonPeriod, typename CommonRep>
158  struct DurationCastImpl<FromDuration, ToDuration, CommonPeriod, CommonRep, true, true>
159  {
160  inline static ToDuration DoCast(const FromDuration& fd)
161  {
162  return ToDuration(static_cast<typename ToDuration::rep>(fd.count()));
163  }
164  };
165 
166  template <typename FromDuration, typename ToDuration, typename CommonPeriod, typename CommonRep>
167  struct DurationCastImpl<FromDuration, ToDuration, CommonPeriod, CommonRep, false, true>
168  {
169  inline static ToDuration DoCast(const FromDuration& d)
170  {
171  return ToDuration(static_cast<typename ToDuration::rep>(static_cast<CommonRep>(d.count()) *
172  static_cast<CommonRep>(CommonPeriod::num)));
173  }
174  };
175 
176  template <typename FromDuration, typename ToDuration, typename CommonPeriod, typename CommonRep>
177  struct DurationCastImpl<FromDuration, ToDuration, CommonPeriod, CommonRep, true, false>
178  {
179  inline static ToDuration DoCast(const FromDuration& d)
180  {
181  return ToDuration(static_cast<typename ToDuration::rep>(static_cast<CommonRep>(d.count()) /
182  static_cast<CommonRep>(CommonPeriod::den)));
183  }
184  };
185 
186  template <typename FromDuration, typename ToDuration, typename CommonPeriod, typename CommonRep>
187  struct DurationCastImpl<FromDuration, ToDuration, CommonPeriod, CommonRep, false, false>
188  {
189  inline static ToDuration DoCast(const FromDuration& d)
190  {
191  return ToDuration(static_cast<typename ToDuration::rep>(static_cast<CommonRep>(d.count()) *
192  static_cast<CommonRep>(CommonPeriod::num) /
193  static_cast<CommonRep>(CommonPeriod::den)));
194  }
195  };
196  }; // namespace Internal
197 
198 
200  // duration_cast
202  template <typename ToDuration, typename Rep, typename Period>
203  inline typename eastl::enable_if<Internal::IsDuration<ToDuration>::value, ToDuration>::type
204  duration_cast(const duration<Rep, Period>& d)
205  {
206  typedef typename duration<Rep, Period>::this_type FromDuration;
208  }
209 
210 
212  // duration
214  template <class Rep, class Period>
215  class duration
216  {
217  Rep mRep;
218 
219  public:
220  typedef Rep rep;
221  typedef Period period;
223 
224  #if defined(EA_COMPILER_NO_DEFAULTED_FUNCTIONS)
225  EA_CONSTEXPR duration()
226  : mRep() {}
227 
228  duration(const duration& other)
229  : mRep(Rep(other.mRep)) {}
230 
231  duration& operator=(const duration& other)
232  { mRep = other.mRep; return *this; }
233  #else
234  EA_CONSTEXPR duration() = default;
235  duration(const duration&) = default;
236  duration& operator=(const duration&) = default;
237  #endif
238 
239 
241  // conversion constructors
243  template <class Rep2>
244  inline EA_CONSTEXPR explicit duration(
245  const Rep2& rep2,
249  : mRep(static_cast<Rep>(rep2)) {}
250 
251 
252  template <class Rep2, class Period2>
253  EA_CONSTEXPR duration(const duration<Rep2, Period2>& d2,
255  (eastl::ratio_divide<Period2, Period>::type::den == 1 &&
257  void>::type** = 0)
258  : mRep(duration_cast<duration>(d2).count()) {}
259 
261  // returns the count of ticks
263  EA_CONSTEXPR Rep count() const { return mRep; }
264 
266  // static accessors of special duration values
268  EA_CONSTEXPR inline static duration zero() { return duration(duration_values<Rep>::zero()); }
269  EA_CONSTEXPR inline static duration min() { return duration(duration_values<Rep>::min()); }
270  EA_CONSTEXPR inline static duration max() { return duration(duration_values<Rep>::max()); }
271 
273  // const arithmetic operations
275  EA_CONSTEXPR inline duration operator+() const { return *this; }
276  EA_CONSTEXPR inline duration operator-() const { return duration(0-mRep); }
277 
279  // arithmetic operations
281  inline duration operator++(int) { return duration(mRep++); }
282  inline duration operator--(int) { return duration(mRep--); }
283  inline duration& operator++() { ++mRep; return *this; }
284  inline duration& operator--() { --mRep; return *this; }
285  inline duration& operator+=(const duration& d) { mRep += d.count(); return *this; }
286  inline duration& operator-=(const duration& d) { mRep -= d.count(); return *this; }
287  inline duration& operator*=(const Rep& rhs) { mRep *= rhs; return *this; }
288  inline duration& operator/=(const Rep& rhs) { mRep /= rhs; return *this; }
289  inline duration& operator%=(const Rep& rhs) { mRep %= rhs; return *this; }
290  inline duration& operator%=(const duration& d) { mRep %= d.count(); return *this; }
291  };
292 
293 
295  // 20.12.5.5, arithmetic operations with durations as arguments
297  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
298  typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type EASTL_FORCE_INLINE
299  operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
300  {
301  typedef typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type common_duration_t;
302  return common_duration_t(common_duration_t(lhs).count() + common_duration_t(rhs).count());
303  }
304 
305  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
306  typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type EASTL_FORCE_INLINE
307  operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
308  {
309  typedef typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type common_duration_t;
310  return common_duration_t(common_duration_t(lhs).count() - common_duration_t(rhs).count());
311  }
312 
313  template <typename Rep1, typename Period1, typename Rep2>
314  duration<typename eastl::common_type<Rep1, Rep2>::type, Period1> EASTL_FORCE_INLINE
315  operator*(const duration<Rep1, Period1>& lhs, const Rep2& rhs)
316  {
317  typedef typename duration<eastl::common_type<Rep1, Rep2>, Period1>::type common_duration_t;
318  return common_duration_t(common_duration_t(lhs).count() * rhs);
319  }
320 
321  template <typename Rep1, typename Rep2, typename Period2>
322  duration<typename eastl::common_type<Rep1, Rep2>::type, Period2> EASTL_FORCE_INLINE
323  operator*(const Rep1& lhs, const duration<Rep2, Period2>& rhs)
324  {
325  typedef duration<typename eastl::common_type<Rep1, Rep2>::type, Period2> common_duration_t;
326  return common_duration_t(lhs * common_duration_t(rhs).count());
327  }
328 
329  template <typename Rep1, typename Period1, typename Rep2>
330  duration<typename eastl::common_type<Rep1, Rep2>::type, Period1> EASTL_FORCE_INLINE
331  operator/(const duration<Rep1, Period1>& lhs, const Rep2& rhs)
332  {
333  typedef duration<typename eastl::common_type<Rep1, Rep2>::type, Period1> common_duration_t;
334  return common_duration_t(common_duration_t(lhs).count() / rhs);
335  }
336 
337  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
338  typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type EASTL_FORCE_INLINE
339  operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
340  {
341  typedef typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type common_duration_t;
342  return common_duration_t(common_duration_t(lhs).count() / common_duration_t(rhs).count());
343  }
344 
345  template <typename Rep1, typename Period1, typename Rep2>
346  duration<typename eastl::common_type<Rep1, Rep2>::type, Period1> EASTL_FORCE_INLINE
347  operator%(const duration<Rep1, Period1>& lhs, const Rep2& rhs)
348  {
349  typedef duration<typename eastl::common_type<Rep1, Rep2>::type, Period1> common_duration_t;
350  return common_duration_t(common_duration_t(lhs).count() % rhs);
351  }
352 
353  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
354  typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type EASTL_FORCE_INLINE
355  operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs)
356  {
357  typedef typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type common_duration_t;
358  return common_duration_t(common_duration_t(lhs).count() % common_duration_t(rhs).count());
359  }
360 
361 
363  // 20.12.5.6, compares two durations
365  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
366  EASTL_FORCE_INLINE bool operator==(const duration<Rep1, Period1>& lhs,
367  const duration<Rep2, Period2>& rhs)
368  {
369  typedef typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type common_duration_t;
370  return common_duration_t(lhs).count() == common_duration_t(rhs).count();
371  }
372 
373  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
374  EASTL_FORCE_INLINE bool operator<(const duration<Rep1, Period1>& lhs,
375  const duration<Rep2, Period2>& rhs)
376  {
377  typedef typename eastl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type common_duration_t;
378  return common_duration_t(lhs).count() < common_duration_t(rhs).count();
379  }
380 
381  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
382  EASTL_FORCE_INLINE bool operator!=(const duration<Rep1, Period1>& lhs,
383  const duration<Rep2, Period2>& rhs)
384  {
385  return !(lhs == rhs);
386  }
387 
388  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
389  EASTL_FORCE_INLINE bool operator<=(const duration<Rep1, Period1>& lhs,
390  const duration<Rep2, Period2>& rhs)
391  {
392  return !(rhs < lhs);
393  }
394 
395  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
396  EASTL_FORCE_INLINE bool operator>(const duration<Rep1, Period1>& lhs,
397  const duration<Rep2, Period2>& rhs)
398  {
399  return rhs < lhs;
400  }
401 
402  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
403  EASTL_FORCE_INLINE bool operator>=(const duration<Rep1, Period1>& lhs,
404  const duration<Rep2, Period2>& rhs)
405  {
406  return !(lhs < rhs);
407  }
408 
409 
411  // standard duration units
413  typedef duration<long long, nano> nanoseconds;
414  typedef duration<long long, micro> microseconds;
415  typedef duration<long long, milli> milliseconds;
416  typedef duration<long long> seconds;
417  typedef duration<int, ratio<60>> minutes;
418  typedef duration<int, ratio<3600>> hours;
419 
420 
422  // 20.12.6, time_point
424  template <typename Clock, typename Duration = typename Clock::duration>
426  {
427  Duration mDuration;
428 
429  public:
430  typedef Clock clock;
431  typedef Duration duration;
432  typedef typename Duration::rep rep;
433  typedef typename Duration::period period;
434 
435  inline EA_CONSTEXPR time_point() : mDuration(Duration::zero()) {}
436  EA_CONSTEXPR explicit time_point(const Duration& other) : mDuration(other) {}
437 
438  template <typename Duration2>
439  inline EA_CONSTEXPR time_point(
442  : mDuration(t.time_since_epoch()) {}
443 
444  EA_CONSTEXPR Duration time_since_epoch() const { return mDuration; }
445 
446  time_point& operator+=(const Duration& d) { mDuration += d; return *this; }
447  time_point& operator-=(const Duration& d) { mDuration -= d; return *this; }
448 
449  static EA_CONSTEXPR time_point min() { return time_point(Duration::min()); }
450  static EA_CONSTEXPR time_point max() { return time_point(Duration::max()); }
451  };
452 
453 
455  // 20.12.6.5, time_point arithmetic
457  template <class Clock, class Duration1, class Rep2, class Period2>
459  operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs)
460  {
462  return common_timepoint_t(lhs.time_since_epoch() + rhs);
463  }
464 
465  template <class Rep1, class Period1, class Clock, class Duration2>
466  inline EA_CONSTEXPR time_point<Clock, typename eastl::common_type<Duration2, duration<Rep1, Period1>>::type>
467  operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs)
468  {
469  typedef time_point<Clock, typename eastl::common_type<Duration2, duration<Rep1, Period1>>::type> common_timepoint_t;
470  return common_timepoint_t(lhs + rhs.time_since_epoch());
471  }
472 
473  template <class Clock, class Duration1, class Rep2, class Period2>
474  inline EA_CONSTEXPR time_point<Clock, typename eastl::common_type<Duration1, duration<Rep2, Period2>>::type>
475  operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs)
476  {
477  typedef time_point<Clock, typename eastl::common_type<Duration1, duration<Rep2, Period2>>::type> common_timepoint_t;
478  return common_timepoint_t(lhs.time_since_epoch() - rhs);
479  }
480 
481  template <class Clock, class Duration1, class Duration2>
482  inline EA_CONSTEXPR typename eastl::common_type<Duration1, Duration2>::type operator-(
483  const time_point<Clock, Duration1>& lhs,
484  const time_point<Clock, Duration2>& rhs)
485  {
486  return lhs.time_since_epoch() - rhs.time_since_epoch();
487  }
488 
489  template <class Clock, class Duration1, class Duration2>
490  inline EA_CONSTEXPR bool operator==(const time_point<Clock, Duration1>& lhs,
491  const time_point<Clock, Duration2>& rhs)
492  {
493  return lhs.time_since_epoch() == rhs.time_since_epoch();
494  }
495 
496  template <class Clock, class Duration1, class Duration2>
497  inline EA_CONSTEXPR bool operator!=(const time_point<Clock, Duration1>& lhs,
498  const time_point<Clock, Duration2>& rhs)
499  {
500  return !(lhs == rhs);
501  }
502 
503  template <class Clock, class Duration1, class Duration2>
504  inline EA_CONSTEXPR bool operator<(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs)
505  {
506  return lhs.time_since_epoch() < rhs.time_since_epoch();
507  }
508 
509  template <class Clock, class Duration1, class Duration2>
510  inline EA_CONSTEXPR bool operator<=(const time_point<Clock, Duration1>& lhs,
511  const time_point<Clock, Duration2>& rhs)
512  {
513  return !(rhs < lhs);
514  }
515 
516  template <class Clock, class Duration1, class Duration2>
517  inline EA_CONSTEXPR bool operator>(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs)
518  {
519  return rhs < lhs;
520  }
521 
522  template <class Clock, class Duration1, class Duration2>
523  inline EA_CONSTEXPR bool operator>=(const time_point<Clock, Duration1>& lhs,
524  const time_point<Clock, Duration2>& rhs)
525  {
526  return !(lhs < rhs);
527  }
528 
529 
531  // 20.12.6.7, time_point_cast
533  template <typename ToDuration, typename Clock, typename Duration>
534  EA_CONSTEXPR time_point<Clock, ToDuration> time_point_cast(
535  const time_point<Clock, Duration>& t,
536  typename eastl::enable_if<Internal::IsDuration<ToDuration>::value>::type** = 0)
537  {
538  return time_point<Clock, ToDuration>(duration_cast<ToDuration>(t.time_since_epoch()));
539  }
540 
541 
543  // 20.12.7, clocks
545 
546  namespace Internal
547  {
548  #if defined(EA_PLATFORM_MICROSOFT) && !defined(EA_PLATFORM_MINGW)
549  #define EASTL_NS_PER_TICK 1
550  #elif defined EA_PLATFORM_SONY
551  #define EASTL_NS_PER_TICK _XTIME_NSECS_PER_TICK
552  #elif defined EA_PLATFORM_POSIX
553  #define EASTL_NS_PER_TICK _XTIME_NSECS_PER_TICK
554  #else
555  #define EASTL_NS_PER_TICK 100
556  #endif
557 
558  #if defined(EA_PLATFORM_POSIX)
559  typedef chrono::nanoseconds::period SystemClock_Period;
560  typedef chrono::nanoseconds::period SteadyClock_Period;
561  #else
562  typedef eastl::ratio_multiply<eastl::ratio<EASTL_NS_PER_TICK, 1>, nano>::type SystemClock_Period;
563  typedef eastl::ratio_multiply<eastl::ratio<EASTL_NS_PER_TICK, 1>, nano>::type SteadyClock_Period;
564  #endif
565 
566 
568  // Internal::GetTicks
570  inline uint64_t GetTicks()
571  {
572  #if defined EA_PLATFORM_MICROSOFT
573  auto queryFrequency = []
574  {
575  LARGE_INTEGER frequency;
576  QueryPerformanceFrequency(&frequency);
577  return double(1000000000.0L / frequency.QuadPart); // nanoseconds per tick
578  };
579 
580  auto queryCounter = []
581  {
582  LARGE_INTEGER counter;
583  QueryPerformanceCounter(&counter);
584  return counter.QuadPart;
585  };
586 
587  EA_DISABLE_VC_WARNING(4640) // warning C4640: construction of local static object is not thread-safe (VS2013)
588  static auto frequency = queryFrequency(); // cache cpu frequency on first call
589  EA_RESTORE_VC_WARNING()
590  return uint64_t(frequency * queryCounter());
591  #elif defined EA_PLATFORM_SONY
592  return sceKernelGetProcessTimeCounter();
593  #elif defined(EA_PLATFORM_APPLE)
594  return mach_absolute_time();
595  #elif defined(EA_PLATFORM_POSIX) // Posix means Linux, Unix, and Macintosh OSX, among others (including Linux-based mobile platforms).
596  #if (defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC))
597  timespec ts;
598  int result = clock_gettime(CLOCK_MONOTONIC, &ts);
599 
600  if (result == -1 && errno == EINVAL)
601  result = clock_gettime(CLOCK_REALTIME, &ts);
602 
603  const uint64_t nNanoseconds = (uint64_t)ts.tv_nsec + ((uint64_t)ts.tv_sec * UINT64_C(1000000000));
604  return nNanoseconds;
605  #else
606  struct timeval tv;
607  gettimeofday(&tv, NULL);
608  const uint64_t nMicroseconds = (uint64_t)tv.tv_usec + ((uint64_t)tv.tv_sec * 1000000);
609  return nMicroseconds;
610  #endif
611  #else
612  #error "chrono not implemented for platform"
613  #endif
614  }
615  } // namespace Internal
616 
617 
619  // system_clock
622  {
623  public:
624  typedef long long rep; // signed arithmetic type representing the number of ticks in the clock's duration
625  typedef Internal::SystemClock_Period period;
626  typedef chrono::duration<rep, period> duration; // duration<rep, period>, capable of representing negative durations
628 
629  // true if the time between ticks is always increases monotonically
630  EA_CONSTEXPR_OR_CONST static bool is_steady = false;
631 
632  // returns a time point representing the current point in time.
633  static time_point now() EA_NOEXCEPT
634  {
635  return time_point(duration(Internal::GetTicks()));
636  }
637  };
638 
639 
641  // steady_clock
644  {
645  public:
646  typedef long long rep; // signed arithmetic type representing the number of ticks in the clock's duration
647  typedef Internal::SteadyClock_Period period;
648  typedef chrono::duration<rep, period> duration; // duration<rep, period>, capable of representing negative durations
650 
651  // true if the time between ticks is always increases monotonically
652  EA_CONSTEXPR_OR_CONST static bool is_steady = true;
653 
654  // returns a time point representing the current point in time.
655  static time_point now() EA_NOEXCEPT
656  {
657  return time_point(duration(Internal::GetTicks()));
658  }
659  };
660 
661 
663  // high_resolution_clock
666 
667 
668 } // namespace chrono
669 
670 
672  // duration common_type specialization
674  template <typename Rep1, typename Period1, typename Rep2, typename Period2>
675  struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>
676  {
679  };
680 
681 
683  // time_point common_type specialization
685  template <typename Clock, typename Duration1, typename Duration2>
686  struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>
687  {
689  };
690 
691 
693  // chrono_literals
695  #if EASTL_USER_LITERALS_ENABLED && EASTL_INLINE_NAMESPACES_ENABLED
696  EA_DISABLE_VC_WARNING(4455) // disable warning C4455: literal suffix identifiers that do not start with an underscore are reserved
697  inline namespace literals
698  {
699  inline namespace chrono_literals
700  {
702  // integer chrono literals
704  EA_CONSTEXPR chrono::hours operator"" h(unsigned long long h) { return chrono::hours(h); }
705  EA_CONSTEXPR chrono::minutes operator"" min(unsigned long long m) { return chrono::minutes(m); }
706  EA_CONSTEXPR chrono::seconds operator"" s(unsigned long long s) { return chrono::seconds(s); }
707  EA_CONSTEXPR chrono::milliseconds operator"" ms(unsigned long long ms) { return chrono::milliseconds(ms); }
708  EA_CONSTEXPR chrono::microseconds operator"" us(unsigned long long us) { return chrono::microseconds(us); }
709  EA_CONSTEXPR chrono::nanoseconds operator"" ns(unsigned long long ns) { return chrono::nanoseconds(ns); }
710 
712  // float chrono literals
714  EA_CONSTEXPR chrono::duration<long double, ratio<3600, 1>> operator"" h(long double h)
715  { return chrono::duration<long double, ratio<3600, 1>>(h); }
716  EA_CONSTEXPR chrono::duration<long double, ratio<60, 1>> operator"" min(long double m)
717  { return chrono::duration<long double, ratio<60, 1>>(m); }
718  EA_CONSTEXPR chrono::duration<long double> operator"" s(long double s)
719  { return chrono::duration<long double>(s); }
720  EA_CONSTEXPR chrono::duration<float, milli> operator"" ms(long double ms)
721  { return chrono::duration<long double, milli>(ms); }
722  EA_CONSTEXPR chrono::duration<float, micro> operator"" us(long double us)
723  { return chrono::duration<long double, micro>(us); }
724  EA_CONSTEXPR chrono::duration<float, nano> operator"" ns(long double ns)
725  { return chrono::duration<long double, nano>(ns); }
726 
727  } // namespace chrono_literals
728  }// namespace literals
729  EA_RESTORE_VC_WARNING() // warning: 4455
730  #endif
731 
732 } // namespace eastl
733 
734 
735 #if EASTL_USER_LITERALS_ENABLED && EASTL_INLINE_NAMESPACES_ENABLED
736 namespace chrono
737 {
738  using namespace eastl::literals::chrono_literals;
739 } // namespace chrono
740 #endif
741 
742 
743 #endif
Definition: chrono.h:216
Definition: chrono.h:644
Definition: chrono.h:622
Definition: chrono.h:426
Definition: numeric_limits.h:267
Definition: ratio.h:109
EA Standard Template Library.
Definition: algorithm.h:288
eastl::iterator_traits< InputIterator >::difference_type count(InputIterator first, InputIterator last, const T &value)
Definition: algorithm.h:1347
T min(std::initializer_list< T > ilist)
Definition: algorithm.h:635
Definition: ratio.h:125
Definition: chrono.h:119
Definition: chrono.h:109
Definition: chrono.h:131
Definition: chrono.h:89
Definition: type_compound.h:663
Definition: type_compound.h:615
Definition: type_traits.h:442
Definition: type_traits.h:263
Definition: type_compound.h:328
Definition: type_fundamental.h:183