xref: /illumos-gate/usr/src/uts/common/sys/time_impl.h (revision fc2512cfb727d49529d8ed99164db871f4829b73)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Implementation-private.  This header should not be included
29  * directly by an application.  The application should instead
30  * include <time.h> which includes this header conditionally
31  * depending on which feature test macros are defined. By default,
32  * this header is included by <time.h>.  X/Open and POSIX
33  * standards requirements result in this header being included
34  * by <time.h> only under a restricted set of conditions.
35  */
36 
37 #ifndef _SYS_TIME_IMPL_H
38 #define	_SYS_TIME_IMPL_H
39 
40 #include <sys/feature_tests.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 #ifndef	_ASM
47 
48 #if !defined(_TIME_T) || __cplusplus >= 199711L
49 #define	_TIME_T
50 typedef	long	time_t;		/* time of day in seconds */
51 #endif	/* _TIME_T */
52 
53 /*
54  * Time expressed in seconds and nanoseconds
55  */
56 
57 typedef struct  timespec {		/* definition per POSIX.4 */
58 	time_t		tv_sec;		/* seconds */
59 	long		tv_nsec;	/* and nanoseconds */
60 } timespec_t;
61 
62 #if defined(_SYSCALL32)
63 
64 #include <sys/types32.h>
65 
66 #define	TIMESPEC32_TO_TIMESPEC(ts, ts32)	{	\
67 	(ts)->tv_sec = (time_t)(ts32)->tv_sec;		\
68 	(ts)->tv_nsec = (ts32)->tv_nsec;		\
69 }
70 
71 #define	TIMESPEC_TO_TIMESPEC32(ts32, ts)	{	\
72 	(ts32)->tv_sec = (time32_t)(ts)->tv_sec;	\
73 	(ts32)->tv_nsec = (ts)->tv_nsec;		\
74 }
75 
76 #define	TIMESPEC_OVERFLOW(ts)		\
77 	((ts)->tv_sec < TIME32_MIN || (ts)->tv_sec > TIME32_MAX)
78 
79 #endif	/* _SYSCALL32 */
80 
81 typedef struct timespec timestruc_t;	/* definition per SVr4 */
82 
83 /*
84  * The following has been left in for backward compatibility. Portable
85  * applications should not use the structure name timestruc.
86  */
87 
88 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
89 #define	timestruc	timespec	/* structure name per SVr4 */
90 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
91 
92 /*
93  * Timer specification
94  */
95 typedef struct itimerspec {		/* definition per POSIX.4 */
96 	struct timespec	it_interval;	/* timer period */
97 	struct timespec	it_value;	/* timer expiration */
98 } itimerspec_t;
99 
100 #if defined(_SYSCALL32)
101 
102 #define	ITIMERSPEC32_TO_ITIMERSPEC(it, it32)	{	\
103 	TIMESPEC32_TO_TIMESPEC(&(it)->it_interval, &(it32)->it_interval); \
104 	TIMESPEC32_TO_TIMESPEC(&(it)->it_value, &(it32)->it_value);	\
105 }
106 
107 #define	ITIMERSPEC_TO_ITIMERSPEC32(it32, it)	{	\
108 	TIMESPEC_TO_TIMESPEC32(&(it32)->it_interval, &(it)->it_interval); \
109 	TIMESPEC_TO_TIMESPEC32(&(it32)->it_value, &(it)->it_value);	\
110 }
111 
112 #define	ITIMERSPEC_OVERFLOW(it)				\
113 	(TIMESPEC_OVERFLOW(&(it)->it_interval) &&	\
114 	TIMESPEC_OVERFLOW(&(it)->it_value))
115 
116 #endif	/* _SYSCALL32 */
117 
118 #endif	/* _ASM */
119 
120 #define	__CLOCK_REALTIME0	0	/* obsolete; same as CLOCK_REALTIME */
121 #define	CLOCK_VIRTUAL		1	/* thread's user-level CPU clock */
122 #define	CLOCK_THREAD_CPUTIME_ID	2	/* thread's user+system CPU clock */
123 #define	CLOCK_REALTIME		3	/* wall clock */
124 #define	CLOCK_MONOTONIC		4	/* high resolution monotonic clock */
125 #define	CLOCK_PROCESS_CPUTIME_ID 5	/* process's user+system CPU clock */
126 #define	CLOCK_HIGHRES		CLOCK_MONOTONIC		/* alternate name */
127 #define	CLOCK_PROF		CLOCK_THREAD_CPUTIME_ID	/* alternate name */
128 
129 #ifdef _KERNEL
130 #define	CLOCK_MAX		6
131 #endif
132 
133 #define	TIMER_RELTIME	0x0		/* set timer relative */
134 #define	TIMER_ABSTIME	0x1		/* set timer absolute */
135 
136 #ifdef	__cplusplus
137 }
138 #endif
139 
140 #endif	/* _SYS_TIME_IMPL_H */
141