49 #define AA_CLOCK CLOCK_MONOTONIC
53 static inline struct timespec
63 static inline struct timespec
70 static inline struct timespec
71 aa_tm_add( struct timespec t1, struct timespec t0 ) {
73 t1.tv_nsec + t0.tv_nsec );
77 static inline struct timespec
78 aa_tm_sub( const struct timespec a, const struct timespec b ) {
80 a.tv_nsec - b.tv_nsec );
84 static inline struct timespec
87 clock_gettime( AA_CLOCK, &t );
92 static inline struct timespec
99 aa_tm_cmp(
const struct timespec t1,
const struct timespec t2 ) {
100 return ( t1.tv_sec != t2.tv_sec ) ?
101 (t1.tv_sec - t2.tv_sec) :
102 (t1.tv_nsec - t2.tv_nsec);
106 static inline struct timespec
107 aa_tm_min( const struct timespec t1, const struct timespec t2 ) {
112 static inline struct timespec
113 aa_tm_max( const struct timespec t1, const struct timespec t2 ) {
124 static inline int64_t
126 return t.tv_sec*1000000 + t.tv_nsec/1000;
130 static inline int64_t
132 return t.tv_sec*1000 + t.tv_nsec/1000000;
138 return (
double)t.tv_sec + (double)t.tv_nsec/1e9;
142 static inline struct timespec
144 time_t sec = (time_t) t;
155 r = nanosleep( &t, &rem );
156 assert( 0 == r || EINTR == errno );
157 t.tv_sec = rem.tv_sec;
158 t.tv_nsec = rem.tv_nsec;
164 #if (defined(__GNUC__) || defined(__ICC)) && (defined(__i386__) || defined(__x86_64__))
165 #define AA_FEATURE_RDTSC
166 AA_API uint64_t aa_rdtsc(
void);
171 #endif //AMINO_TIME_H
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_now()
gets current time via AA_CLOCK
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