49 #ifdef CLOCK_MONOTONIC
54 #define AA_CLOCK CLOCK_MONOTONIC
68 static inline struct timespec
78 static inline struct timespec
85 static inline struct timespec
86 aa_tm_add( struct timespec t1, struct timespec t0 ) {
88 t1.tv_nsec + t0.tv_nsec );
92 static inline struct timespec
93 aa_tm_sub( const struct timespec a, const struct timespec b ) {
95 a.tv_nsec - b.tv_nsec );
103 static inline struct timespec
110 aa_tm_cmp(
const struct timespec t1,
const struct timespec t2 ) {
111 return ( t1.tv_sec != t2.tv_sec ) ?
112 (t1.tv_sec - t2.tv_sec) :
113 (t1.tv_nsec - t2.tv_nsec);
117 static inline struct timespec
118 aa_tm_min( const struct timespec t1, const struct timespec t2 ) {
123 static inline struct timespec
124 aa_tm_max( const struct timespec t1, const struct timespec t2 ) {
135 static inline int64_t
137 return t.tv_sec*1000000 + t.tv_nsec/1000;
141 static inline int64_t
143 return t.tv_sec*1000 + t.tv_nsec/1000000;
149 return (
double)t.tv_sec + (double)t.tv_nsec/1e9;
153 static inline struct timespec
155 time_t sec = (time_t) t;
166 r = nanosleep( &t, &rem );
167 assert( 0 == r || EINTR == errno );
168 t.tv_sec = rem.tv_sec;
169 t.tv_nsec = rem.tv_nsec;
175 #if (defined(__GNUC__) || defined(__ICC)) && (defined(__i386__) || defined(__x86_64__))
176 #define AA_FEATURE_RDTSC
177 AA_API uint64_t aa_rdtsc(
void);
#define AA_IBILLION
(int) 1e9
#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 struct timespec aa_tm_future(const struct timespec reltime)
returns reltime + now
AA_API struct timespec aa_tm_now()
gets current time via AA_CLOCK
static struct timespec aa_tm_sub(const struct timespec a, const struct timespec b)
subtract two times: a - b
static int64_t aa_tm_timespec2usec(const struct timespec t)
convert timespec t to microseconds
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 struct timespec aa_tm_sec2timespec(double t)
convert seconds t to timespec
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_min(const struct timespec t1, const struct timespec t2)
Return the earlier of t1, t2.
static int64_t aa_tm_timespec2msec(const struct timespec t)
convert timespec t to milliseconds
static int aa_tm_isafter(const struct timespec abstime)
is the current time later than abstime?
static struct timespec aa_tm_max(const struct timespec t1, const struct timespec t2)
Return the latter of t1, t2.
static double aa_tm_timespec2sec(const struct timespec t)
convert timespec t to seconds
static struct timespec aa_tm_make(time_t sec, long nsec)
create a struct timespec with given elements
static int aa_tm_relsleep(struct timespec t)
sleep for specified time