Annotation of Gnu-Mach/include/mach/time_value.h, revision 1.1.1.2

1.1       root        1: /* 
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989,1988,1987 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  [email protected]
                     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: #ifndef        _MACH_TIME_VALUE_H_
                     28: #define        _MACH_TIME_VALUE_H_
                     29: 
                     30: #include <mach/machine/vm_types.h>
                     31: 
                     32: /*
                     33:  *     Time value returned by kernel.
                     34:  */
                     35: 
                     36: struct time_value {
                     37:        integer_t       seconds;
                     38:        integer_t       microseconds;
                     39: };
                     40: typedef        struct time_value       time_value_t;
                     41: 
                     42: /*
                     43:  *     Macros to manipulate time values.  Assume that time values
                     44:  *     are normalized (microseconds <= 999999).
                     45:  */
                     46: #define        TIME_MICROS_MAX (1000000)
                     47: 
1.1.1.2 ! root       48: #define time_value_assert(val)                 \
        !            49:   assert(0 <= (val)->microseconds && (val)->microseconds < TIME_MICROS_MAX);
        !            50: 
1.1       root       51: #define        time_value_add_usec(val, micros)        {       \
1.1.1.2 ! root       52:        time_value_assert(val);                         \
1.1       root       53:        if (((val)->microseconds += (micros))           \
                     54:                >= TIME_MICROS_MAX) {                   \
                     55:            (val)->microseconds -= TIME_MICROS_MAX;     \
                     56:            (val)->seconds++;                           \
                     57:        }                                               \
1.1.1.2 ! root       58:        time_value_assert(val);                         \
1.1       root       59: }
                     60: 
1.1.1.2 ! root       61: #define        time_value_sub_usec(val, micros)        {       \
        !            62:        time_value_assert(val);                         \
        !            63:        if (((val)->microseconds -= (micros)) < 0) {    \
        !            64:            (val)->microseconds += TIME_MICROS_MAX;     \
        !            65:            (val)->seconds--;                           \
        !            66:        }                                               \
        !            67:        time_value_assert(val);                         \
1.1       root       68: }
                     69: 
1.1.1.2 ! root       70: #define        time_value_add(result, addend) {                        \
        !            71:     time_value_assert(addend);                                 \
        !            72:     (result)->seconds += (addend)->seconds;                    \
        !            73:     time_value_add_usec(result, (addend)->microseconds);       \
        !            74:   }
        !            75: 
        !            76: #define        time_value_sub(result, subtrahend) {                    \
        !            77:     time_value_assert(subtrahend);                             \
        !            78:     (result)->seconds -= (subtrahend)->seconds;                        \
        !            79:     time_value_sub_usec(result, (subtrahend)->microseconds);   \
        !            80:   }
        !            81: 
1.1       root       82: /*
                     83:  *     Time value available through the mapped-time interface.
                     84:  *     Read this mapped value with
                     85:  *             do {
                     86:  *                     secs = mtime->seconds;
1.1.1.2 ! root       87:  *                     __sync_synchronize();
1.1       root       88:  *                     usecs = mtime->microseconds;
1.1.1.2 ! root       89:  *                     __sync_synchronize();
1.1       root       90:  *             } while (secs != mtime->check_seconds);
                     91:  */
                     92: 
                     93: typedef struct mapped_time_value {
                     94:        integer_t seconds;
                     95:        integer_t microseconds;
                     96:        integer_t check_seconds;
                     97: } mapped_time_value_t;
                     98: 
1.1.1.2 ! root       99: /* Macros for converting between struct timespec and time_value_t. */
        !           100: 
        !           101: #define TIME_VALUE_TO_TIMESPEC(tv, ts) do {                             \
        !           102:         (ts)->tv_sec = (tv)->seconds;                                   \
        !           103:         (ts)->tv_nsec = (tv)->microseconds * 1000;                      \
        !           104: } while(0)
        !           105: 
        !           106: #define TIMESPEC_TO_TIME_VALUE(tv, ts) do {                             \
        !           107:         (tv)->seconds = (ts)->tv_sec;                                   \
        !           108:         (tv)->microseconds = (ts)->tv_nsec / 1000;                      \
        !           109: } while(0)
        !           110: 
1.1       root      111: #endif /* _MACH_TIME_VALUE_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.