|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Copyright (c) 1995 NeXT Computer, Inc.
27: *
28: * Interim clock/timer control API.
29: *
30: * HISTORY
31: *
32: * 4 June 1995 ? at NeXT
33: * Created.
34: */
35:
36: #ifndef _KERN_CLOCK_H_
37: #define _KERN_CLOCK_H_
38:
39: #import <mach/clock_types.h>
40: #import <machdep/machine/mach_param.h>
41: #import <kern/macro_help.h>
42:
43: #define TICKS_PER_SEC HZ
44: #define NSEC_PER_TICK (NSEC_PER_SEC/TICKS_PER_SEC)
45:
46: #define TVALSPEC_SEC_MAX (0 - 1)
47: #define TVALSPEC_NSEC_MAX (NSEC_PER_SEC - 1)
48:
49: #define TVALSPEC_MAX ((tvalspec_t) { TVALSPEC_SEC_MAX, TVALSPEC_NSEC_MAX } )
50: #define TVALSPEC_ZERO ((tvalspec_t) { 0, 0 } )
51:
52: #define ADD_TVALSPEC_NSEC(t1, nsec) \
53: MACRO_BEGIN \
54: (t1)->tv_nsec += (clock_res_t)(nsec); \
55: if ((clock_res_t)(nsec) > 0 && (t1)->tv_nsec >= NSEC_PER_SEC) { \
56: (t1)->tv_nsec -= NSEC_PER_SEC; \
57: (t1)->tv_sec += 1; \
58: } \
59: else if ((clock_res_t)(nsec) < 0 && (t1)->tv_nsec < 0) { \
60: (t1)->tv_nsec += NSEC_PER_SEC; \
61: (t1)->tv_sec -= 1; \
62: } \
63: MACRO_END
64:
65: #define UPDATE_MAPPED_TVALSPEC(mtv, tv) \
66: MACRO_BEGIN \
67: if ((mtv) != 0) { \
68: (mtv)->mtv_csec = (tv)->tv_sec; \
69: (mtv)->mtv_nsec = (tv)->tv_nsec; \
70: (mtv)->mtv_sec = (tv)->tv_sec; \
71: } \
72: MACRO_END
73:
74: extern tvalspec_t ticks_to_tvalspec(
75: unsigned int ticks);
76:
77: typedef enum {
78: Calendar, /* assumed battery back-up */
79: System /* assumed "highest resolution available" */
80: } clock_type_t;
81:
82: extern tvalspec_t clock_get_counter(
83: clock_type_t which_clock);
84:
85: extern void clock_set_counter(
86: clock_type_t which_clock,
87: tvalspec_t value);
88:
89: extern void clock_adjust_counter(
90: clock_type_t which_clock,
91: clock_res_t nsec);
92:
93: extern mapped_tvalspec_t *clock_map_counter(
94: clock_type_t which_clock);
95:
96: typedef enum {
97: SystemWide /* system-wide event timer */
98: } timer_type_t;
99:
100: extern void timer_set_deadline(
101: timer_type_t which_timer,
102: tvalspec_t deadline);
103:
104: typedef void (*timer_func_t)(
105: tvalspec_t timestamp);
106:
107: extern void timer_set_expire_func(
108: timer_type_t which_timer,
109: timer_func_t func);
110:
111: #endif /* _KERN_CLOCK_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.