17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate/*
287c478bdstevel@tonic-gate * Implementation-private.  This header should not be included
297c478bdstevel@tonic-gate * directly by an application.  The application should instead
307c478bdstevel@tonic-gate * include <time.h> which includes this header conditionally
317c478bdstevel@tonic-gate * depending on which feature test macros are defined. By default,
327c478bdstevel@tonic-gate * this header is included by <time.h>.  X/Open and POSIX
337c478bdstevel@tonic-gate * standards requirements result in this header being included
347c478bdstevel@tonic-gate * by <time.h> only under a restricted set of conditions.
357c478bdstevel@tonic-gate */
367c478bdstevel@tonic-gate
377c478bdstevel@tonic-gate#ifndef _SYS_TIME_IMPL_H
387c478bdstevel@tonic-gate#define	_SYS_TIME_IMPL_H
397c478bdstevel@tonic-gate
407c478bdstevel@tonic-gate#include <sys/feature_tests.h>
417c478bdstevel@tonic-gate
427c478bdstevel@tonic-gate#ifdef	__cplusplus
437c478bdstevel@tonic-gateextern "C" {
447c478bdstevel@tonic-gate#endif
457c478bdstevel@tonic-gate
467c478bdstevel@tonic-gate#ifndef	_ASM
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gate#if !defined(_TIME_T) || __cplusplus >= 199711L
497c478bdstevel@tonic-gate#define	_TIME_T
507c478bdstevel@tonic-gatetypedef	long	time_t;		/* time of day in seconds */
517c478bdstevel@tonic-gate#endif	/* _TIME_T */
527c478bdstevel@tonic-gate
537c478bdstevel@tonic-gate/*
547c478bdstevel@tonic-gate * Time expressed in seconds and nanoseconds
557c478bdstevel@tonic-gate */
567c478bdstevel@tonic-gate
577c478bdstevel@tonic-gatetypedef struct  timespec {		/* definition per POSIX.4 */
587c478bdstevel@tonic-gate	time_t		tv_sec;		/* seconds */
597c478bdstevel@tonic-gate	long		tv_nsec;	/* and nanoseconds */
607c478bdstevel@tonic-gate} timespec_t;
617c478bdstevel@tonic-gate
627c478bdstevel@tonic-gate#if defined(_SYSCALL32)
637c478bdstevel@tonic-gate
647c478bdstevel@tonic-gate#include <sys/types32.h>
657c478bdstevel@tonic-gate
667c478bdstevel@tonic-gate#define	TIMESPEC32_TO_TIMESPEC(ts, ts32)	{	\
677c478bdstevel@tonic-gate	(ts)->tv_sec = (time_t)(ts32)->tv_sec;		\
687c478bdstevel@tonic-gate	(ts)->tv_nsec = (ts32)->tv_nsec;		\
697c478bdstevel@tonic-gate}
707c478bdstevel@tonic-gate
717c478bdstevel@tonic-gate#define	TIMESPEC_TO_TIMESPEC32(ts32, ts)	{	\
727c478bdstevel@tonic-gate	(ts32)->tv_sec = (time32_t)(ts)->tv_sec;	\
737c478bdstevel@tonic-gate	(ts32)->tv_nsec = (ts)->tv_nsec;		\
747c478bdstevel@tonic-gate}
757c478bdstevel@tonic-gate
767c478bdstevel@tonic-gate#define	TIMESPEC_OVERFLOW(ts)		\
777c478bdstevel@tonic-gate	((ts)->tv_sec < TIME32_MIN || (ts)->tv_sec > TIME32_MAX)
787c478bdstevel@tonic-gate
797c478bdstevel@tonic-gate#endif	/* _SYSCALL32 */
807c478bdstevel@tonic-gate
817c478bdstevel@tonic-gatetypedef struct timespec timestruc_t;	/* definition per SVr4 */
827c478bdstevel@tonic-gate
837c478bdstevel@tonic-gate/*
847c478bdstevel@tonic-gate * The following has been left in for backward compatibility. Portable
857c478bdstevel@tonic-gate * applications should not use the structure name timestruc.
867c478bdstevel@tonic-gate */
877c478bdstevel@tonic-gate
887c478bdstevel@tonic-gate#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
897c478bdstevel@tonic-gate#define	timestruc	timespec	/* structure name per SVr4 */
907c478bdstevel@tonic-gate#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
917c478bdstevel@tonic-gate
927c478bdstevel@tonic-gate/*
937c478bdstevel@tonic-gate * Timer specification
947c478bdstevel@tonic-gate */
957c478bdstevel@tonic-gatetypedef struct itimerspec {		/* definition per POSIX.4 */
967c478bdstevel@tonic-gate	struct timespec	it_interval;	/* timer period */
977c478bdstevel@tonic-gate	struct timespec	it_value;	/* timer expiration */
987c478bdstevel@tonic-gate} itimerspec_t;
997c478bdstevel@tonic-gate
1007c478bdstevel@tonic-gate#if defined(_SYSCALL32)
1017c478bdstevel@tonic-gate
1027c478bdstevel@tonic-gate#define	ITIMERSPEC32_TO_ITIMERSPEC(it, it32)	{	\
1037c478bdstevel@tonic-gate	TIMESPEC32_TO_TIMESPEC(&(it)->it_interval, &(it32)->it_interval); \
1047c478bdstevel@tonic-gate	TIMESPEC32_TO_TIMESPEC(&(it)->it_value, &(it32)->it_value);	\
1057c478bdstevel@tonic-gate}
1067c478bdstevel@tonic-gate
1077c478bdstevel@tonic-gate#define	ITIMERSPEC_TO_ITIMERSPEC32(it32, it)	{	\
1087c478bdstevel@tonic-gate	TIMESPEC_TO_TIMESPEC32(&(it32)->it_interval, &(it)->it_interval); \
1097c478bdstevel@tonic-gate	TIMESPEC_TO_TIMESPEC32(&(it32)->it_value, &(it)->it_value);	\
1107c478bdstevel@tonic-gate}
1117c478bdstevel@tonic-gate
1127c478bdstevel@tonic-gate#define	ITIMERSPEC_OVERFLOW(it)				\
1137c478bdstevel@tonic-gate	(TIMESPEC_OVERFLOW(&(it)->it_interval) &&	\
1147c478bdstevel@tonic-gate	TIMESPEC_OVERFLOW(&(it)->it_value))
1157c478bdstevel@tonic-gate
1167c478bdstevel@tonic-gate#endif	/* _SYSCALL32 */
1177c478bdstevel@tonic-gate
1187c478bdstevel@tonic-gate#endif	/* _ASM */
1197c478bdstevel@tonic-gate
1207c478bdstevel@tonic-gate#define	__CLOCK_REALTIME0	0	/* obsolete; same as CLOCK_REALTIME */
1217c478bdstevel@tonic-gate#define	CLOCK_VIRTUAL		1	/* thread's user-level CPU clock */
1227c478bdstevel@tonic-gate#define	CLOCK_THREAD_CPUTIME_ID	2	/* thread's user+system CPU clock */
1237c478bdstevel@tonic-gate#define	CLOCK_REALTIME		3	/* wall clock */
1247c478bdstevel@tonic-gate#define	CLOCK_MONOTONIC		4	/* high resolution monotonic clock */
1257c478bdstevel@tonic-gate#define	CLOCK_PROCESS_CPUTIME_ID 5	/* process's user+system CPU clock */
1267c478bdstevel@tonic-gate#define	CLOCK_HIGHRES		CLOCK_MONOTONIC		/* alternate name */
1277c478bdstevel@tonic-gate#define	CLOCK_PROF		CLOCK_THREAD_CPUTIME_ID	/* alternate name */
1287c478bdstevel@tonic-gate
1297c478bdstevel@tonic-gate#ifdef _KERNEL
1307c478bdstevel@tonic-gate#define	CLOCK_MAX		6
1317c478bdstevel@tonic-gate#endif
1327c478bdstevel@tonic-gate
1337c478bdstevel@tonic-gate#define	TIMER_RELTIME	0x0		/* set timer relative */
1347c478bdstevel@tonic-gate#define	TIMER_ABSTIME	0x1		/* set timer absolute */
1357c478bdstevel@tonic-gate
1367c478bdstevel@tonic-gate#ifdef	__cplusplus
1377c478bdstevel@tonic-gate}
1387c478bdstevel@tonic-gate#endif
1397c478bdstevel@tonic-gate
1407c478bdstevel@tonic-gate#endif	/* _SYS_TIME_IMPL_H */
141