Tizen 2.1 base
[platform/upstream/gcd.git] / dispatch-1.0 / dispatch / time.h
1 /*
2  * Copyright (c) 2008-2009 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 __DISPATCH_BEGIN_DECLS
32
33 struct timespec;
34
35 // 6368156
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
45 #ifdef NSEC_PER_MSEC
46 #undef NSEC_PER_MSEC
47 #endif
48 #define NSEC_PER_SEC 1000000000ull
49 #define NSEC_PER_MSEC 1000000ull
50 #define USEC_PER_SEC 1000000ull
51 #define NSEC_PER_USEC 1000ull
52
53 /*!
54  * @typedef dispatch_time_t
55  *
56  * @abstract
57  * An somewhat abstract representation of time; where zero means "now" and
58  * DISPATCH_TIME_FOREVER means "infinity" and every value in between is an
59  * opaque encoding.
60  */
61 typedef uint64_t dispatch_time_t;
62
63 #define DISPATCH_TIME_NOW 0
64 #define DISPATCH_TIME_FOREVER (~0ull)
65
66 /*!
67  * @function dispatch_time
68  *
69  * @abstract
70  * Create dispatch_time_t relative to the default clock or modify an existing
71  * dispatch_time_t.
72  *
73  * @discussion
74  * On Mac OS X the default clock is based on mach_absolute_time().
75  *
76  * @param when
77  * An optional dispatch_time_t to add nanoseconds to. If zero is passed, then
78  * dispatch_time() will use the result of mach_absolute_time().
79  *
80  * @param delta
81  * Nanoseconds to add.
82  *
83  * @result
84  * A new dispatch_time_t.
85  */
86 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
87 DISPATCH_EXPORT DISPATCH_NOTHROW
88 dispatch_time_t
89 dispatch_time(dispatch_time_t when, int64_t delta);
90
91 /*!
92  * @function dispatch_walltime
93  *
94  * @abstract
95  * Create a dispatch_time_t using the wall clock.
96  *
97  * @discussion
98  * On Mac OS X the wall clock is based on gettimeofday(3).
99  *
100  * @param when
101  * A struct timespect to add time to. If NULL is passed, then
102  * dispatch_walltime() will use the result of gettimeofday(3).
103  *
104  * @param delta
105  * Nanoseconds to add.
106  *
107  * @result
108  * A new dispatch_time_t.
109  */
110 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
111 DISPATCH_EXPORT DISPATCH_NOTHROW
112 dispatch_time_t
113 dispatch_walltime(const struct timespec *when, int64_t delta);
114
115 __DISPATCH_END_DECLS
116
117 #endif