]> git.saurik.com Git - apple/libdispatch.git/blob - dispatch/time.h
libdispatch-913.30.4.tar.gz
[apple/libdispatch.git] / dispatch / time.h
1 /*
2 * Copyright (c) 2008-2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_APACHE_LICENSE_HEADER_START@
5 *
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
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
31 // <rdar://problem/6368156&7563559>
32 #if TARGET_OS_MAC
33 #include <mach/clock_types.h>
34 #endif
35
36 DISPATCH_ASSUME_NONNULL_BEGIN
37
38 #ifdef NSEC_PER_SEC
39 #undef NSEC_PER_SEC
40 #endif
41 #ifdef USEC_PER_SEC
42 #undef USEC_PER_SEC
43 #endif
44 #ifdef NSEC_PER_USEC
45 #undef NSEC_PER_USEC
46 #endif
47 #ifdef NSEC_PER_MSEC
48 #undef NSEC_PER_MSEC
49 #endif
50 #define NSEC_PER_SEC 1000000000ull
51 #define NSEC_PER_MSEC 1000000ull
52 #define USEC_PER_SEC 1000000ull
53 #define NSEC_PER_USEC 1000ull
54
55 __BEGIN_DECLS
56
57 struct timespec;
58
59 /*!
60 * @typedef dispatch_time_t
61 *
62 * @abstract
63 * A somewhat abstract representation of time; where zero means "now" and
64 * DISPATCH_TIME_FOREVER means "infinity" and every value in between is an
65 * opaque encoding.
66 */
67 typedef uint64_t dispatch_time_t;
68
69 #define DISPATCH_TIME_NOW (0ull)
70 #define DISPATCH_TIME_FOREVER (~0ull)
71
72 /*!
73 * @function dispatch_time
74 *
75 * @abstract
76 * Create dispatch_time_t relative to the default clock or modify an existing
77 * dispatch_time_t.
78 *
79 * @discussion
80 * On Mac OS X the default clock is based on mach_absolute_time().
81 *
82 * @param when
83 * An optional dispatch_time_t to add nanoseconds to. If zero is passed, then
84 * dispatch_time() will use the result of mach_absolute_time().
85 *
86 * @param delta
87 * Nanoseconds to add.
88 *
89 * @result
90 * A new dispatch_time_t.
91 */
92 API_AVAILABLE(macos(10.6), ios(4.0))
93 DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW
94 dispatch_time_t
95 dispatch_time(dispatch_time_t when, int64_t delta);
96
97 /*!
98 * @function dispatch_walltime
99 *
100 * @abstract
101 * Create a dispatch_time_t using the wall clock.
102 *
103 * @discussion
104 * On Mac OS X the wall clock is based on gettimeofday(3).
105 *
106 * @param when
107 * A struct timespec to add time to. If NULL is passed, then
108 * dispatch_walltime() will use the result of gettimeofday(3).
109 *
110 * @param delta
111 * Nanoseconds to add.
112 *
113 * @result
114 * A new dispatch_time_t.
115 */
116 API_AVAILABLE(macos(10.6), ios(4.0))
117 DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW
118 dispatch_time_t
119 dispatch_walltime(const struct timespec *_Nullable when, int64_t delta);
120
121 __END_DECLS
122
123 DISPATCH_ASSUME_NONNULL_END
124
125 #endif