time.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1982, 1986, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *      This product includes software developed by the University of
00016  *      California, Berkeley and its contributors.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  *      @(#)time.h      8.5 (Berkeley) 5/4/95
00034  */
00035 #ifndef __SYSINTERF_TIME_H__
00036 #define __SYSINTERF_TIME_H__
00037 
00038 /*
00039  * Structure returned by gettimeofday(2) system call,
00040  * and used in other calls.
00041  */
00042 struct timeval {
00043         long    tv_sec;         /* seconds */
00044         long    tv_usec;        /* and microseconds */
00045 };
00046 
00047 /*
00048  * Structure defined by POSIX.1b to be like a timeval.
00049  */
00050 struct timespec {
00051         time_t  tv_sec;         /* seconds */
00052         long    tv_nsec;        /* and nanoseconds */
00053 };
00054 
00055 #define TIMEVAL_TO_TIMESPEC(tv, ts) {                                   \
00056         (ts)->tv_sec = (tv)->tv_sec;                                    \
00057         (ts)->tv_nsec = (tv)->tv_usec * 1000;                           \
00058 }
00059 #define TIMESPEC_TO_TIMEVAL(tv, ts) {                                   \
00060         (tv)->tv_sec = (ts)->tv_sec;                                    \
00061         (tv)->tv_usec = (ts)->tv_nsec / 1000;                           \
00062 }
00063 
00064 /*
00065  * Note: timezone is obsolete. All timezone handling is now in
00066  * userland. Its just here for back compatibility.
00067  */
00068 struct timezone {
00069         int     tz_minuteswest; /* minutes west of Greenwich */
00070         int     tz_dsttime;     /* type of dst correction */
00071 };
00072 
00073 /* Operations on timevals. */
00074 #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
00075 #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
00076 #define timercmp(tvp, uvp, cmp)                                         \
00077         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
00078             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
00079             ((tvp)->tv_sec cmp (uvp)->tv_sec))
00080 #define timeradd(tvp, uvp, vvp)                                         \
00081         do {                                                            \
00082                 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;          \
00083                 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;       \
00084                 if ((vvp)->tv_usec >= 1000000) {                        \
00085                         (vvp)->tv_sec++;                                \
00086                         (vvp)->tv_usec -= 1000000;                      \
00087                 }                                                       \
00088         } while (/* CONSTCOND */ 0)
00089 #define timersub(tvp, uvp, vvp)                                         \
00090         do {                                                            \
00091                 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;          \
00092                 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;       \
00093                 if ((vvp)->tv_usec < 0) {                               \
00094                         (vvp)->tv_sec--;                                \
00095                         (vvp)->tv_usec += 1000000;                      \
00096                 }                                                       \
00097         } while (/* CONSTCOND */ 0)
00098 
00099 /* Operations on timespecs. */
00100 #define timespecclear(tsp)              (tsp)->tv_sec = (tsp)->tv_nsec = 0
00101 #define timespecisset(tsp)              ((tsp)->tv_sec || (tsp)->tv_nsec)
00102 #define timespeccmp(tsp, usp, cmp)                                      \
00103         (((tsp)->tv_sec == (usp)->tv_sec) ?                             \
00104             ((tsp)->tv_nsec cmp (usp)->tv_nsec) :                       \
00105             ((tsp)->tv_sec cmp (usp)->tv_sec))
00106 #define timespecadd(tsp, usp, vsp)                                      \
00107         do {                                                            \
00108                 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;          \
00109                 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;       \
00110                 if ((vsp)->tv_nsec >= 1000000000L) {                    \
00111                         (vsp)->tv_sec++;                                \
00112                         (vsp)->tv_nsec -= 1000000000L;                  \
00113                 }                                                       \
00114         } while (/* CONSTCOND */ 0)
00115 #define timespecsub(tsp, usp, vsp)                                      \
00116         do {                                                            \
00117                 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
00118                 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
00119                 if ((vsp)->tv_nsec < 0) {                               \
00120                         (vsp)->tv_sec--;                                \
00121                         (vsp)->tv_nsec += 1000000000L;                  \
00122                 }                                                       \
00123         } while (/* CONSTCOND */ 0)
00124 
00125 /*
00126  * Names of the interval timers, and structure
00127  * defining a timer setting.
00128  */
00129 #define ITIMER_REAL     0
00130 #define ITIMER_VIRTUAL  1
00131 #define ITIMER_PROF     2
00132 
00133 struct  itimerval {
00134         struct  timeval it_interval;    /* timer interval */
00135         struct  timeval it_value;       /* current value */
00136 };
00137 
00138 /*
00139  * Getkerninfo clock information structure
00140  */
00141 struct clockinfo {
00142         int     hz;             /* clock frequency */
00143         int     tick;           /* micro-seconds per hz tick */
00144         int     tickadj;        /* clock skew rate for adjtime() */
00145         int     stathz;         /* statistics clock frequency */
00146         int     profhz;         /* profiling clock frequency */
00147 };
00148 
00149 #define CLOCK_REALTIME  0
00150 #define CLOCK_VIRTUAL   1
00151 #define CLOCK_PROF      2
00152 #define CLOCK_MONOTONIC 3
00153 
00154 #define TIMER_RELTIME   0x0     /* relative timer */
00155 #define TIMER_ABSTIME   0x1     /* absolute timer */
00156 
00157 #endif
00158 

Generated on Wed May 24 23:04:17 2006 for LSE/OS by  doxygen 1.4.6