os/ossrv/genericopenlibs/openenvcore/include/sys/time.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*-
sl@0
     2
 * Copyright (c) 1982, 1986, 1993
sl@0
     3
 *	The Regents of the University of California.  All rights reserved.
sl@0
     4
 *
sl@0
     5
 * Redistribution and use in source and binary forms, with or without
sl@0
     6
 * modification, are permitted provided that the following conditions
sl@0
     7
 * are met:
sl@0
     8
 * 1. Redistributions of source code must retain the above copyright
sl@0
     9
 *    notice, this list of conditions and the following disclaimer.
sl@0
    10
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    11
 *    notice, this list of conditions and the following disclaimer in the
sl@0
    12
 *    documentation and/or other materials provided with the distribution.
sl@0
    13
 * 4. Neither the name of the University nor the names of its contributors
sl@0
    14
 *    may be used to endorse or promote products derived from this software
sl@0
    15
 *    without specific prior written permission.
sl@0
    16
 *
sl@0
    17
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
sl@0
    18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sl@0
    19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
sl@0
    20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
sl@0
    21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
sl@0
    22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
sl@0
    23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
sl@0
    25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
sl@0
    26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
sl@0
    27
 * SUCH DAMAGE.
sl@0
    28
 * © * Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0
    29
 *	@(#)time.h	8.5 (Berkeley) 5/4/95
sl@0
    30
 * $FreeBSD: src/sys/sys/time.h,v 1.69 2005/04/02 12:33:27 das Exp $
sl@0
    31
 */
sl@0
    32
sl@0
    33
#ifndef _SYS_TIME_H_
sl@0
    34
#define _SYS_TIME_H_
sl@0
    35
sl@0
    36
#include <sys/_timeval.h>
sl@0
    37
#include <sys/types.h>
sl@0
    38
#include <sys/timespec.h>
sl@0
    39
sl@0
    40
struct timezone {
sl@0
    41
	int	tz_minuteswest;	/* minutes west of Greenwich */
sl@0
    42
	int	tz_dsttime;	/* type of dst correction */
sl@0
    43
};
sl@0
    44
#define	DST_NONE	0	/* not on dst */
sl@0
    45
#define	DST_USA		1	/* USA style dst */
sl@0
    46
#define	DST_AUST	2	/* Australian style dst */
sl@0
    47
#define	DST_WET		3	/* Western European dst */
sl@0
    48
#define	DST_MET		4	/* Middle European dst */
sl@0
    49
#define	DST_EET		5	/* Eastern European dst */
sl@0
    50
#define	DST_CAN		6	/* Canada */
sl@0
    51
sl@0
    52
#if __BSD_VISIBLE
sl@0
    53
struct bintime {
sl@0
    54
	time_t	sec;
sl@0
    55
	uint64_t frac;
sl@0
    56
};
sl@0
    57
sl@0
    58
static __inline void
sl@0
    59
bintime_addx(struct bintime *bt, uint64_t x)
sl@0
    60
{
sl@0
    61
	uint64_t u;
sl@0
    62
sl@0
    63
	u = bt->frac;
sl@0
    64
	bt->frac += x;
sl@0
    65
	if (u > bt->frac)
sl@0
    66
		bt->sec++;
sl@0
    67
}
sl@0
    68
sl@0
    69
static __inline void
sl@0
    70
bintime_add(struct bintime *bt, const struct bintime *bt2)
sl@0
    71
{
sl@0
    72
	uint64_t u;
sl@0
    73
sl@0
    74
	u = bt->frac;
sl@0
    75
	bt->frac += bt2->frac;
sl@0
    76
	if (u > bt->frac)
sl@0
    77
		bt->sec++;
sl@0
    78
	bt->sec += bt2->sec;
sl@0
    79
}
sl@0
    80
sl@0
    81
static __inline void
sl@0
    82
bintime_sub(struct bintime *bt, const struct bintime *bt2)
sl@0
    83
{
sl@0
    84
	uint64_t u;
sl@0
    85
sl@0
    86
	u = bt->frac;
sl@0
    87
	bt->frac -= bt2->frac;
sl@0
    88
	if (u < bt->frac)
sl@0
    89
		bt->sec--;
sl@0
    90
	bt->sec -= bt2->sec;
sl@0
    91
}
sl@0
    92
sl@0
    93
/*-
sl@0
    94
 * Background information:
sl@0
    95
 *
sl@0
    96
 * When converting between timestamps on parallel timescales of differing
sl@0
    97
 * resolutions it is historical and scientific practice to round down rather
sl@0
    98
 * than doing 4/5 rounding.
sl@0
    99
 *
sl@0
   100
 *   The date changes at midnight, not at noon.
sl@0
   101
 *
sl@0
   102
 *   Even at 15:59:59.999999999 it's not four'o'clock.
sl@0
   103
 *
sl@0
   104
 *   time_second ticks after N.999999999 not after N.4999999999
sl@0
   105
 */
sl@0
   106
sl@0
   107
static __inline void
sl@0
   108
bintime2timespec(const struct bintime *bt, struct timespec *ts)
sl@0
   109
{
sl@0
   110
sl@0
   111
	ts->tv_sec = bt->sec;
sl@0
   112
	ts->tv_nsec = ((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32;
sl@0
   113
}
sl@0
   114
sl@0
   115
static __inline void
sl@0
   116
timespec2bintime(const struct timespec *ts, struct bintime *bt)
sl@0
   117
{
sl@0
   118
sl@0
   119
	bt->sec = ts->tv_sec;
sl@0
   120
	/* 18446744073 = int(2^64 / 1000000000) */
sl@0
   121
	bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; 
sl@0
   122
}
sl@0
   123
sl@0
   124
static __inline void
sl@0
   125
bintime2timeval(const struct bintime *bt, struct timeval *tv)
sl@0
   126
{
sl@0
   127
sl@0
   128
	tv->tv_sec = bt->sec;
sl@0
   129
	tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32;
sl@0
   130
}
sl@0
   131
sl@0
   132
static __inline void
sl@0
   133
timeval2bintime(const struct timeval *tv, struct bintime *bt)
sl@0
   134
{
sl@0
   135
sl@0
   136
	bt->sec = tv->tv_sec;
sl@0
   137
	/* 18446744073709 = int(2^64 / 1000000) */
sl@0
   138
	bt->frac = tv->tv_usec * (uint64_t)18446744073709LL;
sl@0
   139
}
sl@0
   140
#endif /* __BSD_VISIBLE */
sl@0
   141
sl@0
   142
/*
sl@0
   143
 * Names of the interval timers, and structure
sl@0
   144
 * defining a timer setting.
sl@0
   145
 */
sl@0
   146
#define	ITIMER_REAL	0
sl@0
   147
#define	ITIMER_VIRTUAL	1
sl@0
   148
#define	ITIMER_PROF	2
sl@0
   149
sl@0
   150
struct itimerval {
sl@0
   151
	struct	timeval it_interval;	/* timer interval */
sl@0
   152
	struct	timeval it_value;	/* current value */
sl@0
   153
};
sl@0
   154
sl@0
   155
/*
sl@0
   156
 * Getkerninfo clock information structure
sl@0
   157
 */
sl@0
   158
struct clockinfo {
sl@0
   159
	int	hz;		/* clock frequency */
sl@0
   160
	int	tick;		/* micro-seconds per hz tick */
sl@0
   161
	int	spare;
sl@0
   162
	int	stathz;		/* statistics clock frequency */
sl@0
   163
	int	profhz;		/* profiling clock frequency */
sl@0
   164
};
sl@0
   165
sl@0
   166
#include <time.h>
sl@0
   167
sl@0
   168
#include <sys/cdefs.h>
sl@0
   169
sl@0
   170
__BEGIN_DECLS
sl@0
   171
IMPORT_C int	adjtime(const struct timeval *, struct timeval *);
sl@0
   172
IMPORT_C int	gettimeofday(struct timeval *, struct timezone *);
sl@0
   173
int	settimeofday(const struct timeval *, const struct timezone *);
sl@0
   174
IMPORT_C int	utimes(const char *, const struct timeval *);
sl@0
   175
__END_DECLS
sl@0
   176
sl@0
   177
sl@0
   178
#endif /* !_SYS_TIME_H_ */