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/mach/time_spec.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* 
    2  * Mach Operating System
    3  * Copyright (c) 1993,1992 Carnegie Mellon University
    4  * All Rights Reserved.
    5  * 
    6  * Permission to use, copy, modify and distribute this software and its
    7  * documentation is hereby granted, provided that both the copyright
    8  * notice and this permission notice appear in all copies of the
    9  * software, derivative works or modified versions, and any portions
   10  * thereof, and that both notices appear in supporting documentation.
   11  * 
   12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   15  * 
   16  * Carnegie Mellon requests users of this software to return to
   17  * 
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  * 
   23  * any improvements or extensions that they make and grant Carnegie Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /*
   27  * HISTORY
   28  * $Log:        time_spec.h,v $
   29  * Revision 2.2  93/11/17  17:48:14  dbg
   30  *      Added time_spec_infinite, time_spec_set_infinite.
   31  *      [93/05/12            dbg]
   32  * 
   33  *      Added mapped_time_spec_read.
   34  *      [93/03/26            dbg]
   35  * 
   36  *      64 bit cleanup.
   37  *      [93/02/19            dbg]
   38  * 
   39  *      Merged into microkernel mainline.
   40  * 
   41  *      Created
   42  *      [92/07/02       savage]
   43  * 
   44  */
   45 
   46 /*
   47  *      Type definitions to measure time in seconds and nanoseconds.
   48  *
   49  *      Authors:        Stefan Savage and David Golub, 1992
   50  */
   51 
   52 #ifndef _MACH_TIME_SPEC_H_
   53 #define _MACH_TIME_SPEC_H_
   54 
   55 #include <mach/machine/vm_types.h>
   56 
   57 /*
   58  *      Time values are represented as seconds and nanoseconds.
   59  */
   60 struct time_spec {
   61         natural_t       seconds;
   62         natural_t       nanoseconds;
   63 };
   64 typedef struct time_spec                time_spec_t;
   65 
   66 /*
   67  *      Time value available by mapping time.
   68  *      This contains a check field to allow
   69  *      asynchronous updates.
   70  */
   71 struct mapped_time_spec {
   72         volatile natural_t      seconds;
   73         volatile natural_t      nanoseconds;
   74         volatile natural_t      check_seconds;
   75 };
   76 typedef struct mapped_time_spec         mapped_time_spec_t;
   77 
   78 /*
   79  *      void mapped_time_spec_read(time_spec_t&         result,
   80  *                                 mapped_time_spec_t * mtime)
   81  *
   82  *      Read the mapped time_spec value and produce a
   83  *      consistent time reading.
   84  *
   85  *      Results are passed by lvalue.
   86  */
   87 #define mapped_time_spec_read(result, mtime) \
   88         do { \
   89                 (result).seconds = (mtime)->seconds; \
   90                 (result).nanoseconds = (mtime)->nanoseconds; \
   91         } while ((result).seconds != (mtime)->check_seconds)
   92 
   93 /*
   94  *      Macros to manipulate time values.
   95  *      Assume that all time values are normalized
   96  *      (nanoseconds <= 999,999,999).
   97  *
   98  *      Results are passed by lvalue.
   99  */
  100 #define NANOSEC_PER_SEC         (1000000000)
  101 
  102 /*
  103  *      void time_spec_add_nsec(time_spec_t& result,
  104  *                              unsigned int nanosec)
  105  *
  106  *      Add number of nanoseconds to a time value.
  107  */
  108 #define time_spec_add_nsec(result, nanosec)                             \
  109     (                                                                   \
  110       (void)(                                                           \
  111         (((result).nanoseconds += (nanosec)) >= NANOSEC_PER_SEC)        \
  112         && (                                                            \
  113             (result).nanoseconds -= NANOSEC_PER_SEC,                    \
  114             (result).seconds++                                          \
  115         )                                                               \
  116       )                                                                 \
  117     )
  118 
  119 /*
  120  *      void time_spec_add(time_spec_t& result,
  121  *                         time_spec_t  addend)
  122  *
  123  *      Add addend to result.
  124  */
  125 #define time_spec_add(result, addend)                                   \
  126     (                                                                   \
  127       (void)(                                                           \
  128         (result).seconds += (addend).seconds,                           \
  129         (((result).nanoseconds += (addend).nanoseconds)                 \
  130          >= NANOSEC_PER_SEC)                                            \
  131         && (                                                            \
  132             (result).nanoseconds -= NANOSEC_PER_SEC,                    \
  133             (result).seconds++                                          \
  134         )                                                               \
  135       )                                                                 \
  136     )
  137 
  138 /*
  139  *      void time_spec_subtract(time_spec_t& result,
  140  *                              time_spec_t  minuend)
  141  *
  142  *      Subtract minuend from result.
  143  */
  144 #define time_spec_subtract(result, minuend)                             \
  145     (                                                                   \
  146       (void)(                                                           \
  147         /*                                                              \
  148          *      Use comparison - fields are unsigned.                   \
  149          */                                                             \
  150         (((result).nanoseconds < (minuend).nanoseconds)                 \
  151         && (                                                            \
  152             (result).nanoseconds += NANOSEC_PER_SEC,                    \
  153             (result).seconds--                                          \
  154         )),                                                             \
  155         (result).nanoseconds -= (minuend).nanoseconds,                  \
  156         (result).seconds -= (minuend).seconds                           \
  157       )                                                                 \
  158     )
  159 
  160 /*
  161  *      void time_spec_set(time_spec_t& time,
  162  *                         time_spec_t  newtime)
  163  *
  164  *      Set time to newtime.
  165  */
  166 #define time_spec_set(time, newtime)                                    \
  167     (                                                                   \
  168         (time).seconds = (newtime).seconds,                             \
  169         (time).nanoseconds = (newtime).nanoseconds                      \
  170     )
  171 
  172 /*
  173  *      boolean_t time_spec_leq(time_spec_t time1,
  174  *                              time_spec_t time2)
  175  *
  176  *      Return TRUE if time1 <= time2.
  177  */
  178 #define time_spec_leq(time1, time2)                                     \
  179         ((time1).seconds < (time2).seconds ||                           \
  180             ((time1).seconds == (time2).seconds &&                      \
  181              (time1).nanoseconds <= (time2).nanoseconds))
  182 
  183 /*
  184  *      boolean_t time_spec_lt(time_spec_t time1,
  185  *                             time_spec_t time2)
  186  *
  187  *      Return TRUE if time1 < time2.
  188  */
  189 #define time_spec_lt(time1, time2)                                      \
  190         ((time1).seconds < (time2).seconds ||                           \
  191             ((time1).seconds == (time2).seconds &&                      \
  192              (time1).nanoseconds < (time2).nanoseconds))
  193 
  194 /*
  195  *      void time_spec_set_infinite(time_spec_t& time)
  196  *
  197  *      Set time to an "infinite" value.  Infinity
  198  *      is used to denote no time for periodic timers.
  199  */
  200 #define time_spec_set_infinite(time)                                    \
  201     (                                                                   \
  202         (time).seconds = ~0,                                            \
  203         (time).nanoseconds = NANOSEC_PER_SEC - 1                        \
  204     )
  205 
  206 /*
  207  *      boolean_t time_spec_infinite(time_spec_t time)
  208  *
  209  *      Return TRUE if time_spec is "infinite".
  210  */
  211 #define time_spec_infinite(time)                                        \
  212         ((time).seconds == ~0 &&                                        \
  213          (time).nanoseconds == NANOSEC_PER_SEC - 1)
  214 
  215 /*
  216  *      boolean_t time_spec_nonzero(time_spec_t time)
  217  *
  218  *      Return TRUE if time_spec is not zero.
  219  */
  220 #define time_spec_nonzero(time)                                         \
  221         ((time).nanoseconds || (time).seconds)
  222 
  223 /*
  224  *      boolean_t time_spec_valid(time_spec_t time)
  225  *
  226  *      Return TRUE if time is a valid time representation.
  227  */
  228 #define time_spec_valid(time)                                           \
  229         ((time).nanoseconds < NANOSEC_PER_SEC)
  230 
  231 #endif  /* _MACH_TIMESPEC_H_ */

Cache object: f2e01eb2b622d9533a92cc689fcea618


[ 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.