Changeset daa90e8 in mainline
- Timestamp:
- 2007-07-02T18:30:54Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7b63b6b
- Parents:
- f2f0392
- Location:
- uspace/lib/libc
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/async.c
rf2f0392 rdaa90e8 100 100 #include <assert.h> 101 101 #include <errno.h> 102 #include < time.h>102 #include <sys/time.h> 103 103 #include <arch/barrier.h> 104 104 … … 161 161 static async_client_conn_t client_connection = default_client_connection; 162 162 static async_client_conn_t interrupt_received = default_interrupt_received; 163 164 /** Add microseconds to give timeval */165 static void tv_add(struct timeval *tv, suseconds_t usecs)166 {167 tv->tv_sec += usecs / 1000000;168 tv->tv_usec += usecs % 1000000;169 if (tv->tv_usec > 1000000) {170 tv->tv_sec++;171 tv->tv_usec -= 1000000;172 }173 }174 175 /** Subtract 2 timevals, return microseconds difference */176 static suseconds_t tv_sub(struct timeval *tv1, struct timeval *tv2)177 {178 suseconds_t result;179 180 result = tv1->tv_usec - tv2->tv_usec;181 result += (tv1->tv_sec - tv2->tv_sec) * 1000000;182 183 return result;184 }185 186 /** Compare timeval187 *188 * @return 1 if tv1 > tv2, otherwise 0189 */190 static int tv_gt(struct timeval *tv1, struct timeval *tv2)191 {192 if (tv1->tv_sec > tv2->tv_sec)193 return 1;194 if (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec > tv2->tv_usec)195 return 1;196 return 0;197 }198 static int tv_gteq(struct timeval *tv1, struct timeval *tv2)199 {200 if (tv1->tv_sec > tv2->tv_sec)201 return 1;202 if (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec >= tv2->tv_usec)203 return 1;204 return 0;205 }206 163 207 164 /* Hash table functions */ -
uspace/lib/libc/generic/time.c
rf2f0392 rdaa90e8 54 54 volatile sysarg_t seconds2; 55 55 } *ktime = NULL; 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 } 56 123 57 124 -
uspace/lib/libc/include/sys/time.h
rf2f0392 rdaa90e8 53 53 }; 54 54 55 int gettimeofday(struct timeval *tv, struct timezone *tz); 55 extern void tv_add(struct timeval *tv, suseconds_t usecs); 56 extern suseconds_t tv_sub(struct timeval *tv1, struct timeval *tv2); 57 extern int tv_gt(struct timeval *tv1, struct timeval *tv2); 58 extern int tv_gteq(struct timeval *tv1, struct timeval *tv2); 59 extern int gettimeofday(struct timeval *tv, struct timezone *tz); 56 60 57 61 #endif
Note:
See TracChangeset
for help on using the changeset viewer.