mn_micros.hpp
Go to the documentation of this file.
1 
19 #ifndef _MNTHREAD_MICROS_H_
20 #define _MNTHREAD_MICROS_H_
21 
22 #include "mn_config.hpp"
23 
24 #include <sys/time.h>
25 #include <time.h>
26 
28 
29 namespace mn {
38  unsigned long micros();
43  unsigned long millis();
44 
49  unsigned int get_ticks();
50 
57  unsigned int ticks_to_ms(unsigned int ticks) MN_DEPRECATED;
58 
65  unsigned int ms_to_ticks(unsigned int ms) MN_DEPRECATED;
66 
73  unsigned int seconds_to_ticks(unsigned int ms) MN_DEPRECATED;
74 
81  unsigned int time_to_ms(const struct timeval* time) MN_DEPRECATED;
82 
89  unsigned int time_to_ticks(const struct timeval* time) MN_DEPRECATED;
90 
97  static inline struct timeval operator - (const struct timeval &lhs, const struct timeval &rhs) {
98  int s = lhs.tv_sec - rhs.tv_sec;
99  int ns = lhs.tv_usec - rhs.tv_usec;
100  if (ns < 0) {
101  s--;
102  ns += 1000000;
103  }
104 
105  return timeval{s, ns};
106  }
107 
114  static inline struct timeval operator + (const struct timeval &lhs, const struct timeval &rhs) {
115  int s = lhs.tv_sec + rhs.tv_sec;
116  int ns = lhs.tv_usec + rhs.tv_usec;
117  if (ns >= 1000000) {
118  s++;
119  ns -= 1000000;
120  }
121 
122  return timeval{s, ns};
123  }
124 }
125 
127 
128 #endif
#define MN_DEPRECATED
Definition: mn_defines.hpp:54
#define MN_EXTERNC_BEGINN
Definition: mn_defines.hpp:49
#define MN_EXTERNC_END
Definition: mn_defines.hpp:50
Definition: mn_allocator_typetraits.hpp:25
unsigned int ticks_to_ms(unsigned int ticks) MN_DEPRECATED
Definition: mn_micros.cpp:84
unsigned long millis()
Definition: mn_micros.cpp:62
unsigned int time_to_ticks(const struct timeval *time) MN_DEPRECATED
Definition: mn_micros.cpp:117
unsigned int seconds_to_ticks(unsigned int ms) MN_DEPRECATED
Definition: mn_micros.cpp:98
unsigned long micros()
Definition: mn_micros.cpp:45
unsigned int ms_to_ticks(unsigned int ms) MN_DEPRECATED
Definition: mn_micros.cpp:91
unsigned int time_to_ms(const struct timeval *time) MN_DEPRECATED
Definition: mn_micros.cpp:105
unsigned int get_ticks()
Definition: mn_micros.cpp:73