iFun Engine API  1.0.0-b3630
Great Technology for Great Games
 All Classes Files Functions Variables Typedefs Macros
monotonic_clock.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2015 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
9 #ifndef INCLUDE_FUNAPI_TIME_MONOTONIC_CLOCK_H_
10 #define INCLUDE_FUNAPI_TIME_MONOTONIC_CLOCK_H_
11 
12 #include <stdint.h>
13 #include <time.h>
14 
15 namespace fun {
16 
20  public:
22  typedef int64_t Value;
23 
25  typedef int64_t Duration;
26 
28  static void ToTimespec(const Value &value, struct timespec *ret) {
29  ret->tv_sec = value / (1000 * 1000);
30  ret->tv_nsec = value % (1000 * 1000) * 1000;
31  }
32 
34  static Duration FromSec(int64_t sec) {
35  return sec * 1000 * 1000;
36  }
37 
39  static Duration FromMsec(int64_t msec) {
40  return msec * 1000;
41  }
42 
44  static Duration FromUsec(int64_t usec) {
45  return usec;
46  }
47 
51  static Value Now() {
52  struct timespec now;
53  clock_gettime(CLOCK_MONOTONIC, &now);
54  return now.tv_sec * 1000 * 1000 + now.tv_nsec / 1000;
55  }
56 
57  private:
58  MonotonicClock() { }
59 };
60 
61 } // namespace fun
62 
63 #endif // INCLUDE_FUNAPI_TIME_MONOTONIC_CLOCK_H_
static Duration FromSec(int64_t sec)
Converts sec value into Duration.
Definition: monotonic_clock.h:34
static Duration FromMsec(int64_t msec)
Converts msec value into Duration.
Definition: monotonic_clock.h:39
static Duration FromUsec(int64_t usec)
Converts usec value into Duration.
Definition: monotonic_clock.h:44
static void ToTimespec(const Value &value, struct timespec *ret)
Converts the given Monotonic clock value into timespec.
Definition: monotonic_clock.h:28
Funapi uses MonotonicClock to be overcome clock drift.
Definition: monotonic_clock.h:19
int64_t Duration
duration value in usec.
Definition: monotonic_clock.h:25
static Value Now()
Returns the current Monotonic value.
Definition: monotonic_clock.h:51
int64_t Value
clock value in usec.
Definition: monotonic_clock.h:22