]> git.saurik.com Git - apple/libdispatch.git/blame - dispatch/time.h
libdispatch-339.92.1.tar.gz
[apple/libdispatch.git] / dispatch / time.h
CommitLineData
0ab74447 1/*
e85f4437 2 * Copyright (c) 2008-2011 Apple Inc. All rights reserved.
0ab74447
A
3 *
4 * @APPLE_APACHE_LICENSE_HEADER_START@
e85f4437 5 *
0ab74447
A
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
e85f4437 9 *
0ab74447 10 * http://www.apache.org/licenses/LICENSE-2.0
e85f4437 11 *
0ab74447
A
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
e85f4437 17 *
0ab74447
A
18 * @APPLE_APACHE_LICENSE_HEADER_END@
19 */
20
21#ifndef __DISPATCH_TIME__
22#define __DISPATCH_TIME__
23
24#ifndef __DISPATCH_INDIRECT__
25#error "Please #include <dispatch/dispatch.h> instead of this file directly."
26#include <dispatch/base.h> // for HeaderDoc
27#endif
28
29#include <stdint.h>
30
c093abd6
A
31// <rdar://problem/6368156&7563559>
32#if TARGET_OS_MAC
33#include <mach/clock_types.h>
34#endif
0ab74447 35
0ab74447
A
36#ifdef NSEC_PER_SEC
37#undef NSEC_PER_SEC
38#endif
39#ifdef USEC_PER_SEC
40#undef USEC_PER_SEC
41#endif
42#ifdef NSEC_PER_USEC
43#undef NSEC_PER_USEC
44#endif
e85f4437
A
45#ifdef NSEC_PER_MSEC
46#undef NSEC_PER_MSEC
47#endif
0ab74447 48#define NSEC_PER_SEC 1000000000ull
e85f4437 49#define NSEC_PER_MSEC 1000000ull
0ab74447
A
50#define USEC_PER_SEC 1000000ull
51#define NSEC_PER_USEC 1000ull
52
c093abd6
A
53__BEGIN_DECLS
54
55struct timespec;
56
0ab74447
A
57/*!
58 * @typedef dispatch_time_t
59 *
60 * @abstract
e85f4437 61 * A somewhat abstract representation of time; where zero means "now" and
0ab74447
A
62 * DISPATCH_TIME_FOREVER means "infinity" and every value in between is an
63 * opaque encoding.
64 */
65typedef uint64_t dispatch_time_t;
66
c093abd6 67#define DISPATCH_TIME_NOW (0ull)
0ab74447
A
68#define DISPATCH_TIME_FOREVER (~0ull)
69
70/*!
71 * @function dispatch_time
72 *
73 * @abstract
74 * Create dispatch_time_t relative to the default clock or modify an existing
75 * dispatch_time_t.
76 *
77 * @discussion
78 * On Mac OS X the default clock is based on mach_absolute_time().
79 *
80 * @param when
81 * An optional dispatch_time_t to add nanoseconds to. If zero is passed, then
82 * dispatch_time() will use the result of mach_absolute_time().
83 *
84 * @param delta
85 * Nanoseconds to add.
86 *
87 * @result
88 * A new dispatch_time_t.
89 */
e85f4437
A
90__OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
91DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW
0ab74447
A
92dispatch_time_t
93dispatch_time(dispatch_time_t when, int64_t delta);
94
95/*!
96 * @function dispatch_walltime
97 *
98 * @abstract
99 * Create a dispatch_time_t using the wall clock.
100 *
101 * @discussion
102 * On Mac OS X the wall clock is based on gettimeofday(3).
103 *
104 * @param when
105 * A struct timespect to add time to. If NULL is passed, then
106 * dispatch_walltime() will use the result of gettimeofday(3).
107 *
108 * @param delta
109 * Nanoseconds to add.
110 *
111 * @result
112 * A new dispatch_time_t.
113 */
e85f4437
A
114__OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
115DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW
0ab74447
A
116dispatch_time_t
117dispatch_walltime(const struct timespec *when, int64_t delta);
118
119__END_DECLS
120
121#endif