xref: /titanic_50/usr/src/uts/common/sys/time_impl.h (revision c5c4113dfcabb1eed3d4bdf7609de5170027a794)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 #include <sys/feature_tests.h>
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 #ifndef	_ASM
49 
50 #if !defined(_TIME_T) || __cplusplus >= 199711L
51 #define	_TIME_T
52 typedef	long	time_t;		/* time of day in seconds */
53 #endif	/* _TIME_T */
54 
55 /*
56  * Time expressed in seconds and nanoseconds
57  */
58 
59 typedef struct  timespec {		/* definition per POSIX.4 */
60 	time_t		tv_sec;		/* seconds */
61 	long		tv_nsec;	/* and nanoseconds */
62 } timespec_t;
63 
64 #if defined(_SYSCALL32)
65 
66 #include <sys/types32.h>
67 
68 #define	TIMESPEC32_TO_TIMESPEC(ts, ts32)	{	\
69 	(ts)->tv_sec = (time_t)(ts32)->tv_sec;		\
70 	(ts)->tv_nsec = (ts32)->tv_nsec;		\
71 }
72 
73 #define	TIMESPEC_TO_TIMESPEC32(ts32, ts)	{	\
74 	(ts32)->tv_sec = (time32_t)(ts)->tv_sec;	\
75 	(ts32)->tv_nsec = (ts)->tv_nsec;		\
76 }
77 
78 #define	TIMESPEC_OVERFLOW(ts)		\
79 	((ts)->tv_sec < TIME32_MIN || (ts)->tv_sec > TIME32_MAX)
80 
81 #endif	/* _SYSCALL32 */
82 
83 typedef struct timespec timestruc_t;	/* definition per SVr4 */
84 
85 /*
86  * The following has been left in for backward compatibility. Portable
87  * applications should not use the structure name timestruc.
88  */
89 
90 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
91 #define	timestruc	timespec	/* structure name per SVr4 */
92 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
93 
94 /*
95  * Timer specification
96  */
97 typedef struct itimerspec {		/* definition per POSIX.4 */
98 	struct timespec	it_interval;	/* timer period */
99 	struct timespec	it_value;	/* timer expiration */
100 } itimerspec_t;
101 
102 #if defined(_SYSCALL32)
103 
104 #define	ITIMERSPEC32_TO_ITIMERSPEC(it, it32)	{	\
105 	TIMESPEC32_TO_TIMESPEC(&(it)->it_interval, &(it32)->it_interval); \
106 	TIMESPEC32_TO_TIMESPEC(&(it)->it_value, &(it32)->it_value);	\
107 }
108 
109 #define	ITIMERSPEC_TO_ITIMERSPEC32(it32, it)	{	\
110 	TIMESPEC_TO_TIMESPEC32(&(it32)->it_interval, &(it)->it_interval); \
111 	TIMESPEC_TO_TIMESPEC32(&(it32)->it_value, &(it)->it_value);	\
112 }
113 
114 #define	ITIMERSPEC_OVERFLOW(it)				\
115 	(TIMESPEC_OVERFLOW(&(it)->it_interval) &&	\
116 	TIMESPEC_OVERFLOW(&(it)->it_value))
117 
118 #endif	/* _SYSCALL32 */
119 
120 #endif	/* _ASM */
121 
122 #define	__CLOCK_REALTIME0	0	/* obsolete; same as CLOCK_REALTIME */
123 #define	CLOCK_VIRTUAL		1	/* thread's user-level CPU clock */
124 #define	CLOCK_THREAD_CPUTIME_ID	2	/* thread's user+system CPU clock */
125 #define	CLOCK_REALTIME		3	/* wall clock */
126 #define	CLOCK_MONOTONIC		4	/* high resolution monotonic clock */
127 #define	CLOCK_PROCESS_CPUTIME_ID 5	/* process's user+system CPU clock */
128 #define	CLOCK_HIGHRES		CLOCK_MONOTONIC		/* alternate name */
129 #define	CLOCK_PROF		CLOCK_THREAD_CPUTIME_ID	/* alternate name */
130 
131 #ifdef _KERNEL
132 #define	CLOCK_MAX		6
133 #endif
134 
135 #define	TIMER_RELTIME	0x0		/* set timer relative */
136 #define	TIMER_ABSTIME	0x1		/* set timer absolute */
137 
138 #ifdef	__cplusplus
139 }
140 #endif
141 
142 #endif	/* _SYS_TIME_IMPL_H */
143