The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/time.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: time.h,v 1.45 2005/02/26 22:25:34 perry Exp $  */
    2 
    3 /*
    4  * Copyright (c) 1982, 1986, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)time.h      8.5 (Berkeley) 5/4/95
   32  */
   33 
   34 #ifndef _SYS_TIME_H_
   35 #define _SYS_TIME_H_
   36 
   37 #include <sys/featuretest.h>
   38 #include <sys/types.h>
   39 #ifdef _KERNEL
   40 #include <sys/callout.h>
   41 #include <sys/signal.h>
   42 #include <sys/queue.h>
   43 #endif
   44 
   45 /*
   46  * Structure returned by gettimeofday(2) system call,
   47  * and used in other calls.
   48  */
   49 struct timeval {
   50         long    tv_sec;         /* seconds */
   51         long    tv_usec;        /* and microseconds */
   52 };
   53 
   54 /*
   55  * Structure defined by POSIX.1b to be like a timeval.
   56  */
   57 struct timespec {
   58         time_t  tv_sec;         /* seconds */
   59         long    tv_nsec;        /* and nanoseconds */
   60 };
   61 
   62 #define TIMEVAL_TO_TIMESPEC(tv, ts) do {                                \
   63         (ts)->tv_sec = (tv)->tv_sec;                                    \
   64         (ts)->tv_nsec = (tv)->tv_usec * 1000;                           \
   65 } while (/*CONSTCOND*/0)
   66 #define TIMESPEC_TO_TIMEVAL(tv, ts) do {                                \
   67         (tv)->tv_sec = (ts)->tv_sec;                                    \
   68         (tv)->tv_usec = (ts)->tv_nsec / 1000;                           \
   69 } while (/*CONSTCOND*/0)
   70 
   71 /*
   72  * Note: timezone is obsolete. All timezone handling is now in
   73  * userland. Its just here for back compatibility.
   74  */
   75 struct timezone {
   76         int     tz_minuteswest; /* minutes west of Greenwich */
   77         int     tz_dsttime;     /* type of dst correction */
   78 };
   79 
   80 /* Operations on timevals. */
   81 #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
   82 #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
   83 #define timercmp(tvp, uvp, cmp)                                         \
   84         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
   85             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
   86             ((tvp)->tv_sec cmp (uvp)->tv_sec))
   87 #define timeradd(tvp, uvp, vvp)                                         \
   88         do {                                                            \
   89                 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;          \
   90                 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;       \
   91                 if ((vvp)->tv_usec >= 1000000) {                        \
   92                         (vvp)->tv_sec++;                                \
   93                         (vvp)->tv_usec -= 1000000;                      \
   94                 }                                                       \
   95         } while (/* CONSTCOND */ 0)
   96 #define timersub(tvp, uvp, vvp)                                         \
   97         do {                                                            \
   98                 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;          \
   99                 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;       \
  100                 if ((vvp)->tv_usec < 0) {                               \
  101                         (vvp)->tv_sec--;                                \
  102                         (vvp)->tv_usec += 1000000;                      \
  103                 }                                                       \
  104         } while (/* CONSTCOND */ 0)
  105 
  106 /* Operations on timespecs. */
  107 #define timespecclear(tsp)              (tsp)->tv_sec = (tsp)->tv_nsec = 0
  108 #define timespecisset(tsp)              ((tsp)->tv_sec || (tsp)->tv_nsec)
  109 #define timespeccmp(tsp, usp, cmp)                                      \
  110         (((tsp)->tv_sec == (usp)->tv_sec) ?                             \
  111             ((tsp)->tv_nsec cmp (usp)->tv_nsec) :                       \
  112             ((tsp)->tv_sec cmp (usp)->tv_sec))
  113 #define timespecadd(tsp, usp, vsp)                                      \
  114         do {                                                            \
  115                 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;          \
  116                 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;       \
  117                 if ((vsp)->tv_nsec >= 1000000000L) {                    \
  118                         (vsp)->tv_sec++;                                \
  119                         (vsp)->tv_nsec -= 1000000000L;                  \
  120                 }                                                       \
  121         } while (/* CONSTCOND */ 0)
  122 #define timespecsub(tsp, usp, vsp)                                      \
  123         do {                                                            \
  124                 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
  125                 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
  126                 if ((vsp)->tv_nsec < 0) {                               \
  127                         (vsp)->tv_sec--;                                \
  128                         (vsp)->tv_nsec += 1000000000L;                  \
  129                 }                                                       \
  130         } while (/* CONSTCOND */ 0)
  131 
  132 /*
  133  * Names of the interval timers, and structure
  134  * defining a timer setting.
  135  */
  136 #define ITIMER_REAL     0
  137 #define ITIMER_VIRTUAL  1
  138 #define ITIMER_PROF     2
  139 
  140 struct  itimerval {
  141         struct  timeval it_interval;    /* timer interval */
  142         struct  timeval it_value;       /* current value */
  143 };
  144 
  145 /*
  146  * Structure defined by POSIX.1b to be like a itimerval, but with
  147  * timespecs. Used in the timer_*() system calls.
  148  */
  149 struct  itimerspec {
  150         struct  timespec it_interval;
  151         struct  timespec it_value;
  152 };
  153 
  154 /*
  155  * Getkerninfo clock information structure
  156  */
  157 struct clockinfo {
  158         int     hz;             /* clock frequency */
  159         int     tick;           /* micro-seconds per hz tick */
  160         int     tickadj;        /* clock skew rate for adjtime() */
  161         int     stathz;         /* statistics clock frequency */
  162         int     profhz;         /* profiling clock frequency */
  163 };
  164 
  165 #define CLOCK_REALTIME  0
  166 #define CLOCK_VIRTUAL   1
  167 #define CLOCK_PROF      2
  168 #define CLOCK_MONOTONIC 3
  169 
  170 #define TIMER_RELTIME   0x0     /* relative timer */
  171 #define TIMER_ABSTIME   0x1     /* absolute timer */
  172 
  173 #ifdef _KERNEL
  174 /*
  175  * Structure used to manage timers in a process.
  176  */
  177 struct  ptimer {
  178         union {
  179                 struct  callout pt_ch;
  180                 struct {
  181                         LIST_ENTRY(ptimer)      pt_list;
  182                         int     pt_active;
  183                 } pt_nonreal;
  184         } pt_data;
  185         struct  sigevent pt_ev;
  186         struct  itimerval pt_time;
  187         struct  ksiginfo pt_info;
  188         int     pt_overruns;    /* Overruns currently accumulating */
  189         int     pt_poverruns;   /* Overruns associated w/ a delivery */
  190         int     pt_type;
  191         int     pt_entry;
  192         struct proc *pt_proc;
  193 };
  194 
  195 #define pt_ch   pt_data.pt_ch
  196 #define pt_list pt_data.pt_nonreal.pt_list
  197 #define pt_active       pt_data.pt_nonreal.pt_active
  198 
  199 #define TIMER_MAX       32      /* See ptimers->pts_fired if you enlarge this */
  200 #define TIMERS_ALL      0
  201 #define TIMERS_POSIX    1
  202 
  203 LIST_HEAD(ptlist, ptimer);
  204 
  205 struct  ptimers {
  206         struct ptlist pts_virtual;
  207         struct ptlist pts_prof;
  208         struct ptimer *pts_timers[TIMER_MAX];
  209         int pts_fired;
  210 };
  211 
  212 int     itimerfix(struct timeval *tv);
  213 int     itimerdecr(struct ptimer *, int);
  214 void    itimerfire(struct ptimer *);
  215 void    microtime(struct timeval *tv);
  216 int     settime(struct timeval *);
  217 int     ratecheck(struct timeval *, const struct timeval *);
  218 int     ppsratecheck(struct timeval *, int *, int);
  219 int     settimeofday1(const struct timeval *, const struct timezone *,
  220             struct proc *);
  221 int     adjtime1(const struct timeval *, struct timeval *, struct proc *);
  222 int     clock_settime1(clockid_t, const struct timespec *);
  223 void    timer_settime(struct ptimer *);
  224 void    timer_gettime(struct ptimer *, struct itimerval *);
  225 void    timers_alloc(struct proc *);
  226 void    timers_free(struct proc *, int);
  227 void    realtimerexpire(void *);
  228 #else /* !_KERNEL */
  229 
  230 #ifndef _STANDALONE
  231 #include <time.h>
  232 
  233 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
  234 #include <sys/cdefs.h>
  235 
  236 __BEGIN_DECLS
  237 int     adjtime(const struct timeval *, struct timeval *);
  238 int     futimes(int, const struct timeval [2]);
  239 int     getitimer(int, struct itimerval *);
  240 int     gettimeofday(struct timeval * __restrict, void * __restrict);
  241 int     lutimes(const char *, const struct timeval [2]);
  242 int     setitimer(int, const struct itimerval * __restrict,
  243             struct itimerval * __restrict);
  244 int     settimeofday(const struct timeval * __restrict,
  245             const void * __restrict);
  246 int     utimes(const char *, const struct timeval [2]);
  247 __END_DECLS
  248 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
  249 
  250 #endif  /* !_STANDALONE */
  251 
  252 #endif /* !_KERNEL */
  253 
  254 #endif /* !_SYS_TIME_H_ */

Cache object: f08c7bcc910674b2a2fb5a6a0e426bf2


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.