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