1 .\" Copyright (c) 2008-2013 Apple Inc. All rights reserved.
8 .Nd Calculate temporal milestones
10 .Fd #include <dispatch/dispatch.h>
11 .Vt static const dispatch_time_t DISPATCH_TIME_NOW = 0ull ;
12 .Vt static const dispatch_time_t DISPATCH_TIME_FOREVER = ~0ull ;
15 .Fa "dispatch_time_t base" "int64_t offset"
19 .Fa "struct timespec *base" "int64_t offset"
26 functions provide a simple mechanism for expressing temporal milestones for use
27 with dispatch functions that need timeouts or operate on a schedule.
31 type is a semi-opaque integer, with only the special values
34 .Vt DISPATCH_TIME_FOREVER
35 being externally defined. All other values are represented using an internal
36 format that is not safe for integer arithmetic or comparison.
37 The internal format is subject to change.
41 function returns a milestone relative to an existing milestone after adding
46 parameter maps internally to a wall clock, then the returned value is
47 relative to the wall clock.
51 .Vt DISPATCH_TIME_NOW ,
52 then the current time of the default host clock is used.
56 function is useful for creating a milestone relative to a fixed point in time
57 using the wall clock, as specified by the optional
61 is NULL, then the current time of the wall clock is used.
67 functions detect overflow and underflow conditions when applying the
72 .Vt DISPATCH_TIME_FOREVER
76 .Vt DISPATCH_TIME_FOREVER ,
81 Underflow causes the smallest representable value to be
82 returned for a given clock.
84 Under the C language, untyped numbers default to the
86 type. This can lead to truncation bugs when arithmetic operations with other
87 numbers are expected to generate a
89 sized result, such as the
94 .Fn dispatch_walltime .
97 as a suffix. For example:
98 .Bd -literal -offset indent
102 Create a milestone two seconds in the future:
103 .Bd -literal -offset indent
104 milestone = dispatch_time(DISPATCH_TIME_NOW, 2LL * NSEC_PER_SEC);
107 Create a milestone for use as an infinite timeout:
108 .Bd -literal -offset indent
109 milestone = DISPATCH_TIME_FOREVER;
112 Create a milestone on Tuesday, January 19, 2038:
113 .Bd -literal -offset indent
115 ts.tv_sec = 0x7FFFFFFF;
117 milestone = dispatch_walltime(&ts, 0);
120 These functions return an abstract value for use with
122 .Fn dispatch_group_wait ,
123 .Fn dispatch_semaphore_wait ,
125 .Fn dispatch_source_set_timer .
128 .Xr dispatch_after 3 ,
129 .Xr dispatch_group_create 3 ,
130 .Xr dispatch_semaphore_create 3