Changeset 70 for pjproject/trunk/pjlib/src/pj/os_timestamp_common.c
- Timestamp:
- Nov 21, 2005 4:59:47 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/os_timestamp_common.c
r66 r70 27 27 #define MSEC (1000) 28 28 29 #define u64tohighprec(u64) ((pj_highprec_t)((pj_int64_t)(u64))) 30 29 31 static pj_highprec_t get_elapsed( const pj_timestamp *start, 30 32 const pj_timestamp *stop ) 31 33 { 34 #if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 35 return u64tohighprec(stop->u64 - start->u64); 36 #else 32 37 pj_highprec_t elapsed_hi, elapsed_lo; 33 38 … … 39 44 40 45 return elapsed_hi + elapsed_lo; 46 #endif 47 } 48 49 static pj_highprec_t elapsed_msec( const pj_timestamp *start, 50 const pj_timestamp *stop ) 51 { 52 pj_timestamp ts_freq; 53 pj_highprec_t freq, elapsed; 54 55 if (pj_get_timestamp_freq(&ts_freq) != PJ_SUCCESS) 56 return 0; 57 58 /* Convert frequency timestamp */ 59 #if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 60 freq = u64tohighprec(ts_freq.u64); 61 #else 62 freq = ts_freq.u32.hi; 63 pj_highprec_mul(freq, U32MAX); 64 freq += ts_freq.u32.lo; 65 #endif 66 67 /* Avoid division by zero. */ 68 if (freq == 0) freq = 1; 69 70 /* Get elapsed time in cycles. */ 71 elapsed = get_elapsed(start, stop); 72 73 /* usec = elapsed * MSEC / freq */ 74 pj_highprec_mul(elapsed, MSEC); 75 pj_highprec_div(elapsed, freq); 76 77 return elapsed; 41 78 } 42 79 … … 51 88 52 89 /* Convert frequency timestamp */ 90 #if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 91 freq = u64tohighprec(ts_freq.u64); 92 #else 53 93 freq = ts_freq.u32.hi; 54 94 pj_highprec_mul(freq, U32MAX); 55 95 freq += ts_freq.u32.lo; 96 #endif 56 97 57 98 /* Avoid division by zero. */ … … 78 119 79 120 /* Convert frequency timestamp */ 121 #if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 122 freq = u64tohighprec(ts_freq.u64); 123 #else 80 124 freq = ts_freq.u32.hi; 81 125 pj_highprec_mul(freq, U32MAX); 82 126 freq += ts_freq.u32.lo; 127 #endif 83 128 84 129 /* Avoid division by zero. */ … … 101 146 } 102 147 148 PJ_DEF(pj_uint32_t) pj_elapsed_msec( const pj_timestamp *start, 149 const pj_timestamp *stop ) 150 { 151 return (pj_uint32_t)elapsed_msec(start, stop); 152 } 153 103 154 PJ_DEF(pj_time_val) pj_elapsed_time( const pj_timestamp *start, 104 155 const pj_timestamp *stop ) 105 156 { 106 pj_highprec_t elapsed = elapsed_ usec(start, stop);157 pj_highprec_t elapsed = elapsed_msec(start, stop); 107 158 pj_time_val tv_elapsed; 108 159 … … 114 165 115 166 sec = elapsed; 116 pj_highprec_div(sec, USEC);167 pj_highprec_div(sec, MSEC); 117 168 tv_elapsed.sec = (long)sec; 118 169 119 170 msec = elapsed; 120 pj_highprec_mod(msec, USEC); 121 pj_highprec_div(msec, 1000); 171 pj_highprec_mod(msec, MSEC); 122 172 tv_elapsed.msec = (long)msec; 123 173
Note: See TracChangeset
for help on using the changeset viewer.