xref: /trueos/lib/libdispatch/private/private.h (revision bf5f91cb28c5878845eb00fbf329c042f6c643c9)
1 /*
2  * Copyright (c) 2008-2013 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 /*
22  * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23  * which are subject to change in future releases of Mac OS X. Any applications
24  * relying on these interfaces WILL break.
25  */
26 
27 #ifndef __DISPATCH_PRIVATE__
28 #define __DISPATCH_PRIVATE__
29 
30 #ifdef __APPLE__
31 #include <TargetConditionals.h>
32 #endif
33 
34 #if TARGET_OS_MAC
35 #include <mach/boolean.h>
36 #include <mach/mach.h>
37 #include <mach/message.h>
38 #endif
39 #if HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
42 #if HAVE_SYS_CDEFS_H
43 #include <sys/cdefs.h>
44 #endif
45 #include <pthread.h>
46 
47 #ifndef __DISPATCH_BUILDING_DISPATCH__
48 #include <dispatch/dispatch.h>
49 
50 #ifndef __DISPATCH_INDIRECT__
51 #define __DISPATCH_INDIRECT__
52 #endif
53 
54 #include <dispatch/benchmark.h>
55 #include <dispatch/queue_private.h>
56 #include <dispatch/source_private.h>
57 #include <dispatch/mach_private.h>
58 #include <dispatch/data_private.h>
59 #include <dispatch/io_private.h>
60 #include <dispatch/layout_private.h>
61 
62 #undef __DISPATCH_INDIRECT__
63 
64 #endif /* !__DISPATCH_BUILDING_DISPATCH__ */
65 
66 // <rdar://problem/9627726> Check that public and private dispatch headers match
67 #if DISPATCH_API_VERSION != 20140804 // Keep in sync with <dispatch/dispatch.h>
68 #error "Dispatch header mismatch between /usr/include and /usr/local/include"
69 #endif
70 
71 __BEGIN_DECLS
72 
73 /*!
74  * @function _dispatch_is_multithreaded
75  *
76  * @abstract
77  * Returns true if the current process has become multithreaded by the use
78  * of libdispatch functionality.
79  *
80  * @discussion
81  * This SPI is intended for use by low-level system components that need to
82  * ensure that they do not make a single-threaded process multithreaded, to
83  * avoid negatively affecting child processes of a fork (without exec).
84  *
85  * Such components must not use any libdispatch functionality if this function
86  * returns false.
87  *
88  * @result
89  * Boolean indicating whether the process has used libdispatch and become
90  * multithreaded.
91  */
92 __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
93 DISPATCH_EXPORT DISPATCH_NOTHROW
94 bool _dispatch_is_multithreaded(void);
95 
96 /*!
97  * @function _dispatch_is_fork_of_multithreaded_parent
98  *
99  * @abstract
100  * Returns true if the current process is a child of a parent process that had
101  * become multithreaded by the use of libdispatch functionality at the time of
102  * fork (without exec).
103  *
104  * @discussion
105  * This SPI is intended for use by (rare) low-level system components that need
106  * to continue working on the child side of a fork (without exec) of a
107  * multithreaded process.
108  *
109  * Such components must not use any libdispatch functionality if this function
110  * returns true.
111  *
112  * @result
113  * Boolean indicating whether the parent process had used libdispatch and
114  * become multithreaded at the time of fork.
115  */
116 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
117 DISPATCH_EXPORT DISPATCH_NOTHROW
118 bool _dispatch_is_fork_of_multithreaded_parent(void);
119 
120 /*
121  * dispatch_time convenience macros
122  */
123 
124 #define _dispatch_time_after_nsec(t) \
125 		dispatch_time(DISPATCH_TIME_NOW, (t))
126 #define _dispatch_time_after_usec(t) \
127 		dispatch_time(DISPATCH_TIME_NOW, (t) * NSEC_PER_USEC)
128 #define _dispatch_time_after_msec(t) \
129 		dispatch_time(DISPATCH_TIME_NOW, (t) * NSEC_PER_MSEC)
130 #define _dispatch_time_after_sec(t) \
131 		dispatch_time(DISPATCH_TIME_NOW, (t) * NSEC_PER_SEC)
132 
133 /*
134  * SPI for CoreFoundation/Foundation/libauto ONLY
135  */
136 
137 #define DISPATCH_COCOA_COMPAT (TARGET_OS_MAC || TARGET_OS_WIN32)
138 
139 #if DISPATCH_COCOA_COMPAT
140 
141 #if TARGET_OS_MAC
142 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
143 DISPATCH_EXPORT DISPATCH_CONST DISPATCH_WARN_RESULT DISPATCH_NOTHROW
144 mach_port_t
145 _dispatch_get_main_queue_port_4CF(void);
146 
147 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
148 DISPATCH_EXPORT DISPATCH_NOTHROW
149 void
150 _dispatch_main_queue_callback_4CF(mach_msg_header_t *msg);
151 #elif TARGET_OS_WIN32
152 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
153 DISPATCH_EXPORT DISPATCH_NOTHROW
154 HANDLE
155 _dispatch_get_main_queue_handle_4CF(void);
156 
157 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
158 DISPATCH_EXPORT DISPATCH_NOTHROW
159 void
160 _dispatch_main_queue_callback_4CF(void);
161 #endif // TARGET_OS_WIN32
162 
163 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
164 DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT
165 DISPATCH_NOTHROW
166 dispatch_queue_t
167 _dispatch_runloop_root_queue_create_4CF(const char *label, unsigned long flags);
168 
169 #if TARGET_OS_MAC
170 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
171 DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW
172 mach_port_t
173 _dispatch_runloop_root_queue_get_port_4CF(dispatch_queue_t queue);
174 #endif
175 
176 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
177 DISPATCH_EXPORT DISPATCH_NOTHROW
178 void
179 _dispatch_runloop_root_queue_wakeup_4CF(dispatch_queue_t queue);
180 
181 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
182 DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW
183 bool
184 _dispatch_runloop_root_queue_perform_4CF(dispatch_queue_t queue);
185 
186 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
187 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
188 void
189 _dispatch_source_set_runloop_timer_4CF(dispatch_source_t source,
190 		dispatch_time_t start, uint64_t interval, uint64_t leeway);
191 
192 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
193 DISPATCH_EXPORT
194 void (*dispatch_begin_thread_4GC)(void);
195 
196 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
197 DISPATCH_EXPORT
198 void (*dispatch_end_thread_4GC)(void);
199 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
200 DISPATCH_EXPORT
201 void *(*_dispatch_begin_NSAutoReleasePool)(void);
202 
203 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
204 DISPATCH_EXPORT
205 void (*_dispatch_end_NSAutoReleasePool)(void *);
206 
207 #endif /* DISPATCH_COCOA_COMPAT */
208 
209 __END_DECLS
210 
211 #endif // __DISPATCH_PRIVATE__
212