49 #ifdef CLOCK_MONOTONIC
51 #define AA_CLOCK CLOCK_MONOTONIC
64 static inline struct timespec
74 static inline struct timespec
81 static inline struct timespec
82 aa_tm_add( struct timespec t1, struct timespec t0 ) {
84 t1.tv_nsec + t0.tv_nsec );
88 static inline struct timespec
89 aa_tm_sub( const struct timespec a, const struct timespec b ) {
91 a.tv_nsec - b.tv_nsec );
99 static inline struct timespec
106 aa_tm_cmp(
const struct timespec t1,
const struct timespec t2 ) {
107 return ( t1.tv_sec != t2.tv_sec ) ?
108 (t1.tv_sec - t2.tv_sec) :
109 (t1.tv_nsec - t2.tv_nsec);
113 static inline struct timespec
114 aa_tm_min( const struct timespec t1, const struct timespec t2 ) {
119 static inline struct timespec
120 aa_tm_max( const struct timespec t1, const struct timespec t2 ) {
131 static inline int64_t
133 return t.tv_sec*1000000 + t.tv_nsec/1000;
137 static inline int64_t
139 return t.tv_sec*1000 + t.tv_nsec/1000000;
145 return (
double)t.tv_sec + (double)t.tv_nsec/1e9;
149 static inline struct timespec
151 time_t sec = (time_t) t;
162 r = nanosleep( &t, &rem );
163 assert( 0 == r || EINTR == errno );
164 t.tv_sec = rem.tv_sec;
165 t.tv_nsec = rem.tv_nsec;
171 #if (defined(__GNUC__) || defined(__ICC)) && (defined(__i386__) || defined(__x86_64__))
172 #define AA_FEATURE_RDTSC
173 AA_API uint64_t aa_rdtsc(
void);
178 #endif //AMINO_TIME_H
AA_API struct timespec aa_tm_now()
gets current time via AA_CLOCK
static int aa_tm_isafter(const struct timespec abstime)
is the current time later than abstime?
static struct timespec aa_tm_sec2timespec(double t)
convert seconds t to timespec
static struct timespec aa_tm_make(time_t sec, long nsec)
create a struct timespec with given elements
static double aa_tm_timespec2sec(const struct timespec t)
convert timespec t to seconds
static struct timespec aa_tm_future(const struct timespec reltime)
returns reltime + now
static int64_t aa_tm_timespec2usec(const struct timespec t)
convert timespec t to microseconds
#define AA_IBILLION
(int) 1e9
static long aa_tm_cmp(const struct timespec t1, const struct timespec t2)
t1 < t2: negative; t1 == t2: 0; t1 > t2: positive
static struct timespec aa_tm_max(const struct timespec t1, const struct timespec t2)
Return the latter of t1, t2.
static struct timespec aa_tm_sub(const struct timespec a, const struct timespec b)
subtract two times: a - b
#define AA_API
calling and name mangling convention for functions
static long aa_lmodulo(long a, long b)
Fortran modulo, Ada mod.
static struct timespec aa_tm_add(struct timespec t1, struct timespec t0)
add two times: a + b
static int64_t aa_tm_timespec2msec(const struct timespec t)
convert timespec t to milliseconds
static struct timespec aa_tm_min(const struct timespec t1, const struct timespec t2)
Return the earlier of t1, t2.
static struct timespec aa_tm_make_norm(time_t sec, long nsec)
create a struct timespec with given elements, fixing things up if nsec is negative or more than a bil...
static int aa_tm_relsleep(struct timespec t)
sleep for specified time