#ifndef _SYS_TIME_H
#define _SYS_TIME_H
#include <sys/feature_tests.h>
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
defined(__EXTENSIONS__)
#ifndef _ASM
#if !defined(_TIME_T) || __cplusplus >= 199711L
#define _TIME_T
typedef long time_t;
#endif
#ifndef _SUSECONDS_T
#define _SUSECONDS_T
typedef long suseconds_t;
#endif
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
#if defined(_SYSCALL32)
#include <sys/types32.h>
#define TIMEVAL32_TO_TIMEVAL(tv, tv32) { \
(tv)->tv_sec = (time_t)(tv32)->tv_sec; \
(tv)->tv_usec = (tv32)->tv_usec; \
}
#define TIMEVAL_TO_TIMEVAL32(tv32, tv) { \
(tv32)->tv_sec = (time32_t)(tv)->tv_sec; \
(tv32)->tv_usec = (int32_t)(tv)->tv_usec; \
}
#define TIME32_MAX INT32_MAX
#define TIME32_MIN INT32_MIN
#define TIMEVAL_OVERFLOW(tv) \
((tv)->tv_sec < TIME32_MIN || (tv)->tv_sec > TIME32_MAX)
#endif
#endif
#endif
#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
#ifndef _ASM
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
#endif
#endif
#ifdef __cplusplus
}
#endif
#ifndef _ASM
#include <sys/types.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
#define DST_NONE 0
#define DST_USA 1
#define DST_AUST 2
#define DST_WET 3
#define DST_MET 4
#define DST_EET 5
#define DST_CAN 6
#define DST_GB 7
#define DST_RUM 8
#define DST_TUR 9
#define DST_AUSTALT 10
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
#define timercmp(tvp, uvp, cmp) \
(((tvp)->tv_sec == (uvp)->tv_sec) ? \
\
((tvp)->tv_usec cmp (uvp)->tv_usec) : \
\
((tvp)->tv_sec cmp (uvp)->tv_sec))
#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
#ifdef __lint
#define timeradd(tvp, uvp, vvp) \
do \
{ \
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
if ((vvp)->tv_usec >= 1000000) \
{ \
(vvp)->tv_sec++; \
(vvp)->tv_usec -= 1000000; \
} \
} while ((vvp)->tv_usec >= 1000000)
#define timersub(tvp, uvp, vvp) \
do \
{ \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
if ((vvp)->tv_usec < 0) \
{ \
(vvp)->tv_sec--; \
(vvp)->tv_usec += 1000000; \
} \
} while ((vvp)->tv_usec >= 1000000)
#else
#define timeradd(tvp, uvp, vvp) \
do \
{ \
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
if ((vvp)->tv_usec >= 1000000) \
{ \
(vvp)->tv_sec++; \
(vvp)->tv_usec -= 1000000; \
} \
} while (0)
#define timersub(tvp, uvp, vvp) \
do \
{ \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
if ((vvp)->tv_usec < 0) \
{ \
(vvp)->tv_sec--; \
(vvp)->tv_usec += 1000000; \
} \
} while (0)
#endif
#endif
#if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
#define ITIMER_REAL 0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF 2
#define ITIMER_REALPROF 3
#ifndef _ASM
struct itimerval {
struct timeval it_interval;
struct timeval it_value;
};
#if defined(_SYSCALL32)
struct itimerval32 {
struct timeval32 it_interval;
struct timeval32 it_value;
};
#define ITIMERVAL32_TO_ITIMERVAL(itv, itv32) { \
TIMEVAL32_TO_TIMEVAL(&(itv)->it_interval, &(itv32)->it_interval); \
TIMEVAL32_TO_TIMEVAL(&(itv)->it_value, &(itv32)->it_value); \
}
#define ITIMERVAL_TO_ITIMERVAL32(itv32, itv) { \
TIMEVAL_TO_TIMEVAL32(&(itv32)->it_interval, &(itv)->it_interval); \
TIMEVAL_TO_TIMEVAL32(&(itv32)->it_value, &(itv)->it_value); \
}
#define ITIMERVAL_OVERFLOW(itv) \
(TIMEVAL_OVERFLOW(&(itv)->it_interval) || \
TIMEVAL_OVERFLOW(&(itv)->it_value))
#endif
#endif
#endif
#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
#define SEC 1
#define MILLISEC 1000
#define MICROSEC 1000000
#define NANOSEC 1000000000LL
#define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
#define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
#define USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC))
#define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC))
#define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
#define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
#endif
#ifndef _ASM
typedef longlong_t hrtime_t;
#if defined(_KERNEL) || defined(_FAKE_KERNEL)
#include <sys/time_impl.h>
#include <sys/mutex.h>
extern int tick_per_msec;
extern int msec_per_tick;
extern int usec_per_tick;
extern int nsec_per_tick;
#define TICK_TO_SEC(tick) ((tick) / hz)
#define SEC_TO_TICK(sec) ((sec) * hz)
#define TICK_TO_MSEC(tick) \
(msec_per_tick ? (tick) * msec_per_tick : (tick) / tick_per_msec)
#define MSEC_TO_TICK(msec) \
(msec_per_tick ? (msec) / msec_per_tick : (msec) * tick_per_msec)
#define MSEC_TO_TICK_ROUNDUP(msec) \
(msec_per_tick ? \
((msec) == 0 ? 0 : ((msec) - 1) / msec_per_tick + 1) : \
(msec) * tick_per_msec)
#define TICK_TO_USEC(tick) ((tick) * usec_per_tick)
#define USEC_TO_TICK(usec) ((usec) / usec_per_tick)
#define USEC_TO_TICK_ROUNDUP(usec) \
((usec) == 0 ? 0 : USEC_TO_TICK((usec) - 1) + 1)
#define TICK_TO_NSEC(tick) ((hrtime_t)(tick) * nsec_per_tick)
#define NSEC_TO_TICK(nsec) ((nsec) / nsec_per_tick)
#define NSEC_TO_TICK_ROUNDUP(nsec) \
((nsec) == 0 ? 0 : NSEC_TO_TICK((nsec) - 1) + 1)
#define TICK_TO_TIMEVAL(tick, tvp) { \
clock_t __tmptck = (tick); \
(tvp)->tv_sec = TICK_TO_SEC(__tmptck); \
(tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK((tvp)->tv_sec)); \
}
#define TICK_TO_TIMEVAL32(tick, tvp) { \
clock_t __tmptck = (tick); \
time_t __tmptm = TICK_TO_SEC(__tmptck); \
(tvp)->tv_sec = (time32_t)__tmptm; \
(tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK(__tmptm)); \
}
#define TICK_TO_TIMESTRUC(tick, tsp) { \
clock_t __tmptck = (tick); \
(tsp)->tv_sec = TICK_TO_SEC(__tmptck); \
(tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK((tsp)->tv_sec)); \
}
#define TICK_TO_TIMESTRUC32(tick, tsp) { \
clock_t __tmptck = (tick); \
time_t __tmptm = TICK_TO_SEC(__tmptck); \
(tsp)->tv_sec = (time32_t)__tmptm; \
(tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK(__tmptm)); \
}
#define TIMEVAL_TO_TICK(tvp) \
(SEC_TO_TICK((tvp)->tv_sec) + USEC_TO_TICK((tvp)->tv_usec))
#define TIMESTRUC_TO_TICK(tsp) \
(SEC_TO_TICK((tsp)->tv_sec) + NSEC_TO_TICK((tsp)->tv_nsec))
typedef struct todinfo {
int tod_sec;
int tod_min;
int tod_hour;
int tod_dow;
int tod_day;
int tod_month;
int tod_year;
} todinfo_t;
extern int64_t timedelta;
extern int timechanged;
extern int tod_needsync;
extern kmutex_t tod_lock;
extern volatile timestruc_t hrestime;
extern hrtime_t hres_last_tick;
extern int64_t hrestime_adj;
extern uint_t adj_shift;
extern timestruc_t tod_get(void);
extern void tod_set(timestruc_t);
extern void set_hrestime(timestruc_t *);
extern todinfo_t utc_to_tod(time_t);
extern time_t tod_to_utc(todinfo_t);
extern int hr_clock_lock(void);
extern void hr_clock_unlock(int);
extern hrtime_t gethrtime(void);
extern hrtime_t gethrtime_unscaled(void);
extern hrtime_t gethrtime_max(void);
extern hrtime_t gethrtime_waitfree(void);
extern void scalehrtime(hrtime_t *);
extern uint64_t unscalehrtime(hrtime_t);
extern void gethrestime(timespec_t *);
extern time_t gethrestime_sec(void);
extern void gethrestime_lasttick(timespec_t *);
extern void hrt2ts(hrtime_t, timestruc_t *);
extern hrtime_t ts2hrt(const timestruc_t *);
extern void hrt2tv(hrtime_t, struct timeval *);
extern hrtime_t tv2hrt(struct timeval *);
extern int itimerfix(struct timeval *, int);
extern int itimerdecr(struct itimerval *, int);
extern void timevaladd(struct timeval *, struct timeval *);
extern void timevalsub(struct timeval *, struct timeval *);
extern void timevalfix(struct timeval *);
extern void dtrace_hres_tick(void);
extern clock_t ddi_get_lbolt(void);
extern int64_t ddi_get_lbolt64(void);
#if defined(_SYSCALL32)
extern void hrt2ts32(hrtime_t, timestruc32_t *);
#endif
#endif
#if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
int adjtime(const struct timeval *, struct timeval *);
#endif
#if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || \
defined(_ATFILE_SOURCE) || defined(__EXTENSIONS__)
int futimesat(int, const char *, const struct timeval *);
#endif
#if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
defined(__EXTENSIONS__)
int getitimer(int, struct itimerval *);
int utimes(const char *, const struct timeval *);
#if defined(_XPG4_2)
int setitimer(int, const struct itimerval *_RESTRICT_KYWD,
struct itimerval *_RESTRICT_KYWD);
#else
int setitimer(int, struct itimerval *_RESTRICT_KYWD,
struct itimerval *_RESTRICT_KYWD);
#endif
#endif
#if !defined(_KERNEL) && !defined(_STRICT_SYMBOLS)
int futimes(int, const struct timeval *);
int lutimes(const char *, const struct timeval *);
#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
(tv)->tv_sec = (ts)->tv_sec; \
(tv)->tv_usec = (ts)->tv_nsec / 1000; \
}
#define TIMEVAL_TO_TIMESPEC(tv, ts) { \
(ts)->tv_sec = (tv)->tv_sec; \
(ts)->tv_nsec = (tv)->tv_usec * 1000; \
}
#endif
#if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
#if defined(_SVID_GETTOD)
int settimeofday(struct timeval *);
#else
int settimeofday(struct timeval *, void *);
#endif
hrtime_t gethrtime(void);
hrtime_t gethrvtime(void);
#endif
#if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
defined(__EXTENSIONS__)
#if defined(_SVID_GETTOD)
int gettimeofday(struct timeval *);
#else
int gettimeofday(struct timeval *_RESTRICT_KYWD, void *_RESTRICT_KYWD);
#endif
#endif
#if !defined(_BOOT) && !defined(_KERNEL) && !defined(_FAKE_KERNEL) && \
!defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
#include <time.h>
#endif
#if !defined(_KERNEL) && !defined(_FAKE_KERNEL) && \
!defined(__XOPEN_OR_POSIX) || \
defined(_XPG4_2) || defined(__EXTENSIONS__)
#include <sys/select.h>
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif