OLD | NEW |
(Empty) | |
| 1 /* $OpenBSD: time.h,v 1.11 2000/10/10 13:36:48 itojun Exp $ */ |
| 2 /* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */ |
| 3 |
| 4 /* |
| 5 * Copyright (c) 1982, 1986, 1993 |
| 6 * The Regents of the University of California. All rights reserved. |
| 7 * |
| 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions |
| 10 * are met: |
| 11 * 1. Redistributions of source code must retain the above copyright |
| 12 * notice, this list of conditions and the following disclaimer. |
| 13 * 2. Redistributions in binary form must reproduce the above copyright |
| 14 * notice, this list of conditions and the following disclaimer in the |
| 15 * documentation and/or other materials provided with the distribution. |
| 16 * 3. Neither the name of the University nor the names of its contributors |
| 17 * may be used to endorse or promote products derived from this software |
| 18 * without specific prior written permission. |
| 19 * |
| 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 * SUCH DAMAGE. |
| 31 * |
| 32 * @(#)time.h 8.2 (Berkeley) 7/10/94 |
| 33 */ |
| 34 |
| 35 #ifndef _SYS_TIME_H_ |
| 36 #define _SYS_TIME_H_ |
| 37 |
| 38 #include <sys/types.h> |
| 39 |
| 40 /* |
| 41 * Structure returned by gettimeofday(2) system call, |
| 42 * and used in other calls. |
| 43 */ |
| 44 struct timeval { |
| 45 long tv_sec; /* seconds */ |
| 46 long tv_usec; /* and microseconds */ |
| 47 }; |
| 48 |
| 49 /* |
| 50 * Structure defined by POSIX.1b to be like a timeval. |
| 51 */ |
| 52 struct timespec { |
| 53 time_t tv_sec; /* seconds */ |
| 54 long tv_nsec; /* and nanoseconds */ |
| 55 }; |
| 56 |
| 57 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \ |
| 58 (ts)->tv_sec = (tv)->tv_sec; \ |
| 59 (ts)->tv_nsec = (tv)->tv_usec * 1000; \ |
| 60 } |
| 61 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \ |
| 62 (tv)->tv_sec = (ts)->tv_sec; \ |
| 63 (tv)->tv_usec = (ts)->tv_nsec / 1000; \ |
| 64 } |
| 65 |
| 66 struct timezone { |
| 67 int tz_minuteswest; /* minutes west of Greenwich */ |
| 68 int tz_dsttime; /* type of dst correction */ |
| 69 }; |
| 70 #define DST_NONE 0 /* not on dst */ |
| 71 #define DST_USA 1 /* USA style dst */ |
| 72 #define DST_AUST 2 /* Australian style dst */ |
| 73 #define DST_WET 3 /* Western European dst */ |
| 74 #define DST_MET 4 /* Middle European dst */ |
| 75 #define DST_EET 5 /* Eastern European dst */ |
| 76 #define DST_CAN 6 /* Canada */ |
| 77 |
| 78 /* Operations on timevals. */ |
| 79 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 |
| 80 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) |
| 81 #define timercmp(tvp, uvp, cmp) \ |
| 82 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ |
| 83 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ |
| 84 ((tvp)->tv_sec cmp (uvp)->tv_sec)) |
| 85 #define timeradd(tvp, uvp, vvp) \ |
| 86 do { \ |
| 87 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ |
| 88 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ |
| 89 if ((vvp)->tv_usec >= 1000000) { \ |
| 90 (vvp)->tv_sec++; \ |
| 91 (vvp)->tv_usec -= 1000000; \ |
| 92 } \ |
| 93 } while (0) |
| 94 #define timersub(tvp, uvp, vvp) \ |
| 95 do { \ |
| 96 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ |
| 97 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ |
| 98 if ((vvp)->tv_usec < 0) { \ |
| 99 (vvp)->tv_sec--; \ |
| 100 (vvp)->tv_usec += 1000000; \ |
| 101 } \ |
| 102 } while (0) |
| 103 |
| 104 /* Operations on timespecs. */ |
| 105 #define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0 |
| 106 #define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) |
| 107 #define timespeccmp(tsp, usp, cmp) \ |
| 108 (((tsp)->tv_sec == (usp)->tv_sec) ? \ |
| 109 ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ |
| 110 ((tsp)->tv_sec cmp (usp)->tv_sec)) |
| 111 #define timespecadd(tsp, usp, vsp) \ |
| 112 do { \ |
| 113 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ |
| 114 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ |
| 115 if ((vsp)->tv_nsec >= 1000000000L) { \ |
| 116 (vsp)->tv_sec++; \ |
| 117 (vsp)->tv_nsec -= 1000000000L; \ |
| 118 } \ |
| 119 } while (0) |
| 120 #define timespecsub(tsp, usp, vsp) \ |
| 121 do { \ |
| 122 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ |
| 123 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ |
| 124 if ((vsp)->tv_nsec < 0) { \ |
| 125 (vsp)->tv_sec--; \ |
| 126 (vsp)->tv_nsec += 1000000000L; \ |
| 127 } \ |
| 128 } while (0) |
| 129 |
| 130 /* |
| 131 * Names of the interval timers, and structure |
| 132 * defining a timer setting. |
| 133 */ |
| 134 #define ITIMER_REAL 0 |
| 135 #define ITIMER_VIRTUAL 1 |
| 136 #define ITIMER_PROF 2 |
| 137 |
| 138 struct itimerval { |
| 139 struct timeval it_interval; /* timer interval */ |
| 140 struct timeval it_value; /* current value */ |
| 141 }; |
| 142 |
| 143 /* |
| 144 * Getkerninfo clock information structure |
| 145 */ |
| 146 struct clockinfo { |
| 147 int hz; /* clock frequency */ |
| 148 int tick; /* micro-seconds per hz tick */ |
| 149 int tickadj; /* clock skew rate for adjtime() */ |
| 150 int stathz; /* statistics clock frequency */ |
| 151 int profhz; /* profiling clock frequency */ |
| 152 }; |
| 153 |
| 154 #define CLOCK_REALTIME 0 |
| 155 #define CLOCK_VIRTUAL 1 |
| 156 #define CLOCK_PROF 2 |
| 157 |
| 158 #define TIMER_RELTIME 0x0 /* relative timer */ |
| 159 #define TIMER_ABSTIME 0x1 /* absolute timer */ |
| 160 |
| 161 /* --- stuff got cut here - niels --- */ |
| 162 |
| 163 #endif /* !_SYS_TIME_H_ */ |
OLD | NEW |