Rev 2479 | Rev 2564 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2479 | Rev 2486 | ||
|---|---|---|---|
| Line 52... | Line 52... | ||
| 52 | volatile sysarg_t seconds1; |
52 | volatile sysarg_t seconds1; |
| 53 | volatile sysarg_t useconds; |
53 | volatile sysarg_t useconds; |
| 54 | volatile sysarg_t seconds2; |
54 | volatile sysarg_t seconds2; |
| 55 | } *ktime = NULL; |
55 | } *ktime = NULL; |
| 56 | 56 | ||
| - | 57 | /** Add microseconds to given timeval. |
|
| - | 58 | * |
|
| - | 59 | * @param tv Destination timeval. |
|
| - | 60 | * @param usecs Number of microseconds to add. |
|
| - | 61 | */ |
|
| - | 62 | void tv_add(struct timeval *tv, suseconds_t usecs) |
|
| - | 63 | { |
|
| - | 64 | tv->tv_sec += usecs / 1000000; |
|
| - | 65 | tv->tv_usec += usecs % 1000000; |
|
| - | 66 | if (tv->tv_usec > 1000000) { |
|
| - | 67 | tv->tv_sec++; |
|
| - | 68 | tv->tv_usec -= 1000000; |
|
| - | 69 | } |
|
| - | 70 | } |
|
| - | 71 | ||
| - | 72 | /** Subtract two timevals. |
|
| - | 73 | * |
|
| - | 74 | * @param tv1 First timeval. |
|
| - | 75 | * @param tv2 Second timeval. |
|
| - | 76 | * |
|
| - | 77 | * @return Return difference between tv1 and tv2 (tv1 - tv2) in |
|
| - | 78 | * microseconds. |
|
| - | 79 | */ |
|
| - | 80 | suseconds_t tv_sub(struct timeval *tv1, struct timeval *tv2) |
|
| - | 81 | { |
|
| - | 82 | suseconds_t result; |
|
| - | 83 | ||
| - | 84 | result = tv1->tv_usec - tv2->tv_usec; |
|
| - | 85 | result += (tv1->tv_sec - tv2->tv_sec) * 1000000; |
|
| - | 86 | ||
| - | 87 | return result; |
|
| - | 88 | } |
|
| - | 89 | ||
| - | 90 | /** Decide if one timeval is greater than the other. |
|
| - | 91 | * |
|
| - | 92 | * @param t1 First timeval. |
|
| - | 93 | * @param t2 Second timeval. |
|
| - | 94 | * |
|
| - | 95 | * @return Return true tv1 is greater than tv2. Otherwise return |
|
| - | 96 | * false. |
|
| - | 97 | */ |
|
| - | 98 | int tv_gt(struct timeval *tv1, struct timeval *tv2) |
|
| - | 99 | { |
|
| - | 100 | if (tv1->tv_sec > tv2->tv_sec) |
|
| - | 101 | return 1; |
|
| - | 102 | if (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec > tv2->tv_usec) |
|
| - | 103 | return 1; |
|
| - | 104 | return 0; |
|
| - | 105 | } |
|
| - | 106 | ||
| - | 107 | /** Decide if one timeval is greater than or equal to the other. |
|
| - | 108 | * |
|
| - | 109 | * @param tv1 First timeval. |
|
| - | 110 | * @param tv2 Second timeval. |
|
| - | 111 | * |
|
| - | 112 | * @return Return true if tv1 is greater than or equal to tv2. |
|
| - | 113 | * Otherwise return false. |
|
| - | 114 | */ |
|
| - | 115 | int tv_gteq(struct timeval *tv1, struct timeval *tv2) |
|
| - | 116 | { |
|
| - | 117 | if (tv1->tv_sec > tv2->tv_sec) |
|
| - | 118 | return 1; |
|
| - | 119 | if (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec >= tv2->tv_usec) |
|
| - | 120 | return 1; |
|
| - | 121 | return 0; |
|
| - | 122 | } |
|
| - | 123 | ||
| 57 | 124 | ||
| 58 | /** POSIX gettimeofday |
125 | /** POSIX gettimeofday |
| 59 | * |
126 | * |
| 60 | * The time variables are memory mapped(RO) from kernel, which updates |
127 | * The time variables are memory mapped(RO) from kernel, which updates |
| 61 | * them periodically. As it is impossible to read 2 values atomically, we |
128 | * them periodically. As it is impossible to read 2 values atomically, we |