Changeset 657 for trunk/src/emx/include/sys/time.h
- Timestamp:
- Sep 7, 2003, 9:23:15 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/include/sys/time.h
-
Property cvs2svn:cvs-rev
changed from
1.5
to1.6
r656 r657 1 /* - modified for gcc/os2 by bird 2003 2 * 1 /* 3 2 * Copyright (c) 1982, 1986, 1993 4 3 * The Regents of the University of California. All rights reserved. … … 33 32 * 34 33 * @(#)time.h 8.5 (Berkeley) 5/4/95 35 */ 34 * $FreeBSD: src/sys/sys/time.h,v 1.61 2003/02/23 10:18:31 phk Exp $ 35 */ 36 37 /** @file 38 * FreeBSD 5.1 39 * 40 * @changed EMX isms 41 * @changed IBM TCP paranoia. 42 */ 36 43 37 44 #ifndef _SYS_TIME_H_ 38 45 #define _SYS_TIME_H_ 39 46 40 #include < time.h>47 #include <sys/_timeval.h> 41 48 #include <sys/types.h> 42 43 #if defined (__cplusplus) 44 extern "C" { 45 #endif 46 47 #if !defined (_TIMEVAL) 48 #define _TIMEVAL 49 /** gettimeofday return structure */ 50 struct timeval 51 { 52 /** seconds */ 53 long tv_sec; 54 /** and microseconds */ 55 long tv_usec; 49 #include <sys/timespec.h> 50 51 #if !defined (_TIMEZONE) /* bird: EMX */ 52 #define _TIMEZONE /* bird: EMX */ 53 struct timezone { 54 int tz_minuteswest; /* minutes west of Greenwich */ 55 int tz_dsttime; /* type of dst correction */ 56 56 }; 57 #endif 58 59 #if !defined (_TIMEZONE) 60 #define _TIMEZONE 61 /** Timezone information */ 62 struct timezone 63 { 64 /** minutes west of Greenwich */ 65 int tz_minuteswest; 66 /** type of dst correction. */ 67 int tz_dsttime; 57 #endif /* bird: EMX */ 58 #define DST_NONE 0 /* not on dst */ 59 #define DST_USA 1 /* USA style dst */ 60 #define DST_AUST 2 /* Australian style dst */ 61 #define DST_WET 3 /* Western European dst */ 62 #define DST_MET 4 /* Middle European dst */ 63 #define DST_EET 5 /* Eastern European dst */ 64 #define DST_CAN 6 /* Canada */ 65 66 #if __BSD_VISIBLE 67 struct bintime { 68 time_t sec; 69 uint64_t frac; 68 70 }; 69 #endif 70 71 #if !defined(TCPV40HDRS) && !defined(DST_NONE) 72 #define DST_NONE 0 /* not on dst */ 73 #define DST_USA 1 /* USA style dst. */ 74 #define DST_AUST 2 /* Australian style dst. */ 75 #define DST_WET 3 /* Western European dst. */ 76 #define DST_MET 4 /* Middle European dst. */ 77 #define DST_EET 5 /* Eastern European dst. */ 78 #define DST_CAN 6 /* Canada. */ 79 #endif /* !TCPV40HDRS */ 80 81 #ifndef TCPV40HDRS 82 #pragma pack(4) 83 /** POSIX.4 version of timeval. */ 84 struct timespec { 85 time_t ts_sec; /* seconds */ 86 long ts_nsec; /* and nanoseconds */ 87 }; 88 #pragma pack() 89 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \ 90 (ts)->ts_sec = (tv)->tv_sec; \ 91 (ts)->ts_nsec = (tv)->tv_usec * 1000; \ 92 } 93 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \ 94 (tv)->tv_sec = (ts)->ts_sec; \ 95 (tv)->tv_usec = (ts)->ts_nsec / 1000; \ 96 } 71 72 static __inline void 73 bintime_addx(struct bintime *bt, uint64_t x) 74 { 75 uint64_t u; 76 77 u = bt->frac; 78 bt->frac += x; 79 if (u > bt->frac) 80 bt->sec++; 81 } 82 83 static __inline void 84 bintime_add(struct bintime *bt, struct bintime *bt2) 85 { 86 uint64_t u; 87 88 u = bt->frac; 89 bt->frac += bt2->frac; 90 if (u > bt->frac) 91 bt->sec++; 92 bt->sec += bt2->sec; 93 } 94 95 static __inline void 96 bintime_sub(struct bintime *bt, struct bintime *bt2) 97 { 98 uint64_t u; 99 100 u = bt->frac; 101 bt->frac -= bt2->frac; 102 if (u < bt->frac) 103 bt->sec--; 104 bt->sec -= bt2->sec; 105 } 106 107 /*- 108 * Background information: 109 * 110 * When converting between timestamps on parallel timescales of differing 111 * resolutions it is historical and scientific practice to round down rather 112 * than doing 4/5 rounding. 113 * 114 * The date changes at midnight, not at noon. 115 * 116 * Even at 15:59:59.999999999 it's not four'o'clock. 117 * 118 * time_second ticks after N.999999999 not after N.4999999999 119 */ 120 121 static __inline void 122 bintime2timespec(struct bintime *bt, struct timespec *ts) 123 { 124 125 ts->tv_sec = bt->sec; 126 ts->tv_nsec = ((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32; 127 } 128 129 static __inline void 130 timespec2bintime(struct timespec *ts, struct bintime *bt) 131 { 132 133 bt->sec = ts->tv_sec; 134 /* 18446744073 = int(2^64 / 1000000000) */ 135 bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; 136 } 137 138 static __inline void 139 bintime2timeval(struct bintime *bt, struct timeval *tv) 140 { 141 142 tv->tv_sec = bt->sec; 143 tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32; 144 } 145 146 static __inline void 147 timeval2bintime(struct timeval *tv, struct bintime *bt) 148 { 149 150 bt->sec = tv->tv_sec; 151 /* 18446744073709 = int(2^64 / 1000000) */ 152 bt->frac = tv->tv_usec * (uint64_t)18446744073709LL; 153 } 154 #endif /* __BSD_VISIBLE */ 155 156 #ifdef _KERNEL 157 158 /* Operations on timespecs */ 159 #define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) 160 #define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) 161 #define timespeccmp(tvp, uvp, cmp) \ 162 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 163 ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ 164 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 165 #define timespecadd(vvp, uvp) \ 166 do { \ 167 (vvp)->tv_sec += (uvp)->tv_sec; \ 168 (vvp)->tv_nsec += (uvp)->tv_nsec; \ 169 if ((vvp)->tv_nsec >= 1000000000) { \ 170 (vvp)->tv_sec++; \ 171 (vvp)->tv_nsec -= 1000000000; \ 172 } \ 173 } while (0) 174 #define timespecsub(vvp, uvp) \ 175 do { \ 176 (vvp)->tv_sec -= (uvp)->tv_sec; \ 177 (vvp)->tv_nsec -= (uvp)->tv_nsec; \ 178 if ((vvp)->tv_nsec < 0) { \ 179 (vvp)->tv_sec--; \ 180 (vvp)->tv_nsec += 1000000000; \ 181 } \ 182 } while (0) 97 183 98 184 /* Operations on timevals. */ 99 #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) 100 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 101 #ifndef timercmp 102 #define timercmp(tvp, uvp, cmp) \ 103 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 104 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 105 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 106 #endif 107 #ifndef timeradd 185 186 #define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) 187 #define timevalisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 188 #define timevalcmp(tvp, uvp, cmp) \ 189 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 190 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 191 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 192 193 /* timevaladd and timevalsub are not inlined */ 194 195 #endif /* _KERNEL */ 196 197 #ifndef _KERNEL /* NetBSD/OpenBSD compatible interfaces */ 198 199 #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) 200 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 201 #ifndef timercmp /* bird: TCP paranoia */ 202 #define timercmp(tvp, uvp, cmp) \ 203 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 204 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 205 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 206 #endif /* bird: TCP paranoia */ 207 #ifndef timeradd /* bird: TCP paranoia */ 108 208 #define timeradd(tvp, uvp, vvp) \ 109 209 do { \ … … 115 215 } \ 116 216 } while (0) 117 #endif 118 #if def timersub217 #endif /* bird: TCP paranoia */ 218 #ifndef timersub /* bird: TCP paranoia */ 119 219 #define timersub(tvp, uvp, vvp) \ 120 220 do { \ … … 126 226 } \ 127 227 } while (0) 128 #endif 129 130 /* 131 * Getkerninfo clock information structure 132 */ 133 struct clockinfo { 134 int hz; /* clock frequency */ 135 int tick; /* micro-seconds per hz tick */ 136 int stathz; /* statistics clock frequency */ 137 int profhz; /* profiling clock frequency */ 138 }; 228 #endif /* bird: TCP paranoia */ 229 #endif 139 230 140 231 /* … … 142 233 * defining a timer setting. 143 234 */ 144 #define ITIMER_REAL 0 145 #define ITIMER_VIRTUAL 1 146 #define ITIMER_PROF 2 147 #endif /* !TCPV40HDRS */ 148 149 #pragma pack(4) 150 struct itimerval { 151 struct timeval it_interval; /* timer interval */ 152 struct timeval it_value; /* current value */ 235 #define ITIMER_REAL 0 236 #define ITIMER_VIRTUAL 1 237 #define ITIMER_PROF 2 238 239 #pragma pack(4) /* bird: IBM TCP paranoia */ 240 struct itimerval { 241 struct timeval it_interval; /* timer interval */ 242 struct timeval it_value; /* current value */ 153 243 }; 154 #pragma pack() 155 156 157 #if defined(TCPV40HDRS) || !defined(_POSIX_SOURCE) 158 /* These are libc functions so no _System convention. */ 159 int utimes (__const__ char *, __const__ struct timeval *); 160 int gettimeofday (struct timeval *, struct timezone *); 161 int settimeofday (__const__ struct timeval *, __const__ struct timezone *); 162 163 #ifndef TCPV40HDRS 244 #pragma pack() /* bird: IBM TCP paranoia */ 245 246 /* 247 * Getkerninfo clock information structure 248 */ 249 struct clockinfo { 250 int hz; /* clock frequency */ 251 int tick; /* micro-seconds per hz tick */ 252 #if 0 /* bird: OS/2 TCP doesn't define this. */ 253 int spare; 254 #endif 255 int stathz; /* statistics clock frequency */ 256 int profhz; /* profiling clock frequency */ 257 }; 258 259 /* CLOCK_REALTIME and TIMER_ABSTIME are supposed to be in time.h */ 260 261 #ifndef CLOCK_REALTIME 262 #define CLOCK_REALTIME 0 263 #endif 264 #define CLOCK_VIRTUAL 1 265 #define CLOCK_PROF 2 266 #define CLOCK_MONOTONIC 4 267 268 #define TIMER_RELTIME 0x0 /* relative timer */ 269 #ifndef TIMER_ABSTIME 270 #define TIMER_ABSTIME 0x1 /* absolute timer */ 271 #endif 272 273 #ifdef _KERNEL 274 extern time_t time_second; 275 extern time_t time_uptime; 276 277 /* 278 * Functions for looking at our clock: [get]{bin,nano,micro}[up]time() 279 * 280 * Functions without the "get" prefix returns the best timestamp 281 * we can produce in the given format. 282 * 283 * "bin" == struct bintime == seconds + 64 bit fraction of seconds. 284 * "nano" == struct timespec == seconds + nanoseconds. 285 * "micro" == struct timeval == seconds + microseconds. 286 * 287 * Functions containing "up" returns time relative to boot and 288 * should be used for calculating time intervals. 289 * 290 * Functions without "up" returns GMT time. 291 * 292 * Functions with the "get" prefix returns a less precise result 293 * much faster than the functions without "get" prefix and should 294 * be used where a precision of 10 msec is acceptable or where 295 * performance is priority. (NB: "precision", _not_ "resolution" !) 296 * 297 */ 298 299 void binuptime(struct bintime *bt); 300 void nanouptime(struct timespec *tsp); 301 void microuptime(struct timeval *tvp); 302 303 void bintime(struct bintime *bt); 304 void nanotime(struct timespec *tsp); 305 void microtime(struct timeval *tvp); 306 307 void getbinuptime(struct bintime *bt); 308 void getnanouptime(struct timespec *tsp); 309 void getmicrouptime(struct timeval *tvp); 310 311 void getbintime(struct bintime *bt); 312 void getnanotime(struct timespec *tsp); 313 void getmicrotime(struct timeval *tvp); 314 315 /* Other functions */ 316 int itimerdecr(struct itimerval *itp, int usec); 317 int itimerfix(struct timeval *tv); 318 int ppsratecheck(struct timeval *, int *, int); 319 int ratecheck(struct timeval *, const struct timeval *); 320 void timevaladd(struct timeval *t1, struct timeval *t2); 321 void timevalsub(struct timeval *t1, struct timeval *t2); 322 int tvtohz(struct timeval *tv); 323 #else /* !_KERNEL */ 324 #include <time.h> 325 164 326 #include <sys/cdefs.h> 165 327 328 __BEGIN_DECLS 329 /*int adjtime(const struct timeval *, struct timeval *); bird: TCP */ 330 int futimes(int, const struct timeval *); 331 /*int getitimer(int, struct itimerval *); bird: TCP */ 332 int gettimeofday(struct timeval *, struct timezone *); 333 int lutimes(const char *, const struct timeval *); 334 /*int setitimer(int, const struct itimerval *, struct itimerval *); bird: TCP */ 335 int settimeofday(const struct timeval *, const struct timezone *); 336 int utimes(const char *, const struct timeval *); 337 338 /* bird: TCP, moved some protos from above and down here. */ 339 #if !defined(TCPV40HDRS) 166 340 #ifndef TCPCALL 167 341 #define TCPCALL _System 168 342 #endif 169 170 int TCPCALL adjtime(const struct timeval *, struct timeval *); 171 int TCPCALL getitimer(int, struct itimerval *); 172 int TCPCALL setitimer(int, const struct itimerval *, struct itimerval *); 173 #endif 343 int TCPCALL setitimer(int, const struct itimerval *, struct itimerval *); 344 int TCPCALL adjtime(const struct timeval *, struct timeval *); 345 int TCPCALL getitimer(int, struct itimerval *); 174 346 #endif /* TCPV40HDRS */ 175 176 177 #if defined (__cplusplus) 178 } 179 #endif 180 181 #endif /* not _SYS_TIME_H_ */ 347 /* bird: TCP end */ 348 __END_DECLS 349 350 #endif /* !_KERNEL */ 351 352 #endif /* !_SYS_TIME_H_ */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.