Show
Ignore:
Timestamp:
04/09/08 15:37:35 (9 months ago)
Author:
aturner
Message:

switch to timespec (nanosecond precision) for sleeping. OS X's AbsoluteTime?
methods are really damn accurate! refs #41

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • features/performance/src/common/timer.h

    r1970 r1971  
    5252 
    5353void timerdiv(struct timeval *tvp, float div); 
     54void timesdiv(struct timespec *tvs, float div); 
    5455 
    5556/* convert float time to struct timeval *tvp */ 
     
    6970#endif 
    7071 
     72#ifndef TIMESPEC_TO_TIMEVAL 
     73#define TIMESPEC_TO_TIMEVAL(tv, ts) {           \ 
     74    (tv)->tv_sec = (ts)->tv_sec;                \ 
     75    (tv)->tv_usec = (ts)->tv_nsec / 1000; } 
     76#endif 
     77 
    7178/* zero out a timer */ 
    7279#ifndef timerclear 
    7380#define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0 
     81#endif 
     82 
     83/* zero out a timespec */ 
     84#ifndef timesclear 
     85#define timesclear(tvs)     (tvs)->tv_sec = (tvs)->tv_nsec = 0 
    7486#endif 
    7587 
     
    7890#define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec) 
    7991#endif 
     92 
     93/* is timespec non-zero? */ 
     94#ifndef timesisset 
     95#define timesisset(tvs)         ((tvs)->tv_sec || (tvs)->tv_nsec) 
     96#endif 
     97 
    8098 
    8199/* add tvp and uvp and store in vvp */ 
     
    105123#endif 
    106124 
     125#ifndef timessub 
     126#define timessub(tsp, usp, vsp)                                 \ 
     127        do {                                                                    \ 
     128                (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \ 
     129                (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \ 
     130                if ((vsp)->tv_nsec < 0) {                               \ 
     131                        (vsp)->tv_sec--;                                    \ 
     132                        (vsp)->tv_nsec += 1000000000;           \ 
     133                }                                                                   \ 
     134        } while (0) 
     135#endif 
     136 
    107137/* compare tvp and uvp using cmp */ 
    108138#ifndef timercmp 
     
    111141        ((tvp)->tv_usec cmp (uvp)->tv_usec) :           \ 
    112142        ((tvp)->tv_sec cmp (uvp)->tv_sec)) 
     143#endif 
     144 
     145#ifndef timescmp 
     146#define timescmp(tsp, usp, cmp)                             \ 
     147        (((tsp)->tv_sec == (usp)->tv_sec) ?                 \ 
     148        ((tsp)->tv_nsec cmp (usp)->tv_nsec) :           \ 
     149        ((tsp)->tv_sec cmp (usp)->tv_sec)) 
    113150#endif 
    114151