]> git.saurik.com Git - apple/libdispatch.git/blob - src/event/event_config.h
libdispatch-913.1.6.tar.gz
[apple/libdispatch.git] / src / event / event_config.h
1 /*
2 * Copyright (c) 2016 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_EVENT_EVENT_CONFIG__
22 #define __DISPATCH_EVENT_EVENT_CONFIG__
23
24 #if defined(__linux__)
25 # include <sys/eventfd.h>
26 # define DISPATCH_EVENT_BACKEND_EPOLL 1
27 # define DISPATCH_EVENT_BACKEND_KEVENT 0
28 #elif __has_include(<sys/event.h>)
29 # include <sys/event.h>
30 # define DISPATCH_EVENT_BACKEND_EPOLL 0
31 # define DISPATCH_EVENT_BACKEND_KEVENT 1
32 #else
33 # error unsupported event loop
34 #endif
35
36 #if DISPATCH_DEBUG
37 #define DISPATCH_MGR_QUEUE_DEBUG 1
38 #define DISPATCH_WLH_DEBUG 1
39 #endif
40
41 #ifndef DISPATCH_MGR_QUEUE_DEBUG
42 #define DISPATCH_MGR_QUEUE_DEBUG 0
43 #endif
44
45 #ifndef DISPATCH_WLH_DEBUG
46 #define DISPATCH_WLH_DEBUG 0
47 #endif
48
49 #ifndef DISPATCH_MACHPORT_DEBUG
50 #define DISPATCH_MACHPORT_DEBUG 0
51 #endif
52
53 #ifndef DISPATCH_TIMER_ASSERTIONS
54 #if DISPATCH_DEBUG
55 #define DISPATCH_TIMER_ASSERTIONS 1
56 #else
57 #define DISPATCH_TIMER_ASSERTIONS 0
58 #endif
59 #endif
60
61 #if DISPATCH_TIMER_ASSERTIONS
62 #define DISPATCH_TIMER_ASSERT(a, op, b, text) ({ \
63 typeof(a) _a = (a); \
64 if (unlikely(!(_a op (b)))) { \
65 DISPATCH_CLIENT_CRASH(_a, "Timer: " text); \
66 } \
67 })
68 #else
69 #define DISPATCH_TIMER_ASSERT(a, op, b, text) ((void)0)
70 #endif
71
72 #ifndef EV_VANISHED
73 #define EV_VANISHED 0x0200
74 #endif
75
76 #if DISPATCH_EVENT_BACKEND_KEVENT
77 # if defined(EV_SET_QOS)
78 # define DISPATCH_USE_KEVENT_QOS 1
79 # ifndef KEVENT_FLAG_IMMEDIATE
80 # define KEVENT_FLAG_IMMEDIATE 0x001
81 # endif
82 # ifndef KEVENT_FLAG_ERROR_EVENTS
83 # define KEVENT_FLAG_ERROR_EVENTS 0x002
84 # endif
85 # else
86 # define DISPATCH_USE_KEVENT_QOS 0
87 # endif
88
89 # ifdef NOTE_LEEWAY
90 # define DISPATCH_HAVE_TIMER_COALESCING 1
91 # else
92 # define NOTE_LEEWAY 0
93 # define DISPATCH_HAVE_TIMER_COALESCING 0
94 # endif // !NOTE_LEEWAY
95 # if defined(NOTE_CRITICAL) && defined(NOTE_BACKGROUND)
96 # define DISPATCH_HAVE_TIMER_QOS 1
97 # else
98 # undef NOTE_CRITICAL
99 # define NOTE_CRITICAL 0
100 # undef NOTE_BACKGROUND
101 # define NOTE_BACKGROUND 0
102 # define DISPATCH_HAVE_TIMER_QOS 0
103 # endif // !defined(NOTE_CRITICAL) || !defined(NOTE_BACKGROUND)
104
105 # ifndef NOTE_FUNLOCK
106 # define NOTE_FUNLOCK 0x00000100
107 # endif
108
109 # if HAVE_DECL_NOTE_REAP
110 # if defined(NOTE_REAP) && defined(__APPLE__)
111 # undef NOTE_REAP
112 # define NOTE_REAP 0x10000000 // <rdar://problem/13338526>
113 # endif
114 # endif // HAVE_DECL_NOTE_REAP
115
116 # ifndef VQ_QUOTA
117 # undef HAVE_DECL_VQ_QUOTA // rdar://problem/24160982
118 # endif // VQ_QUOTA
119
120 # ifndef VQ_NEARLOWDISK
121 # undef HAVE_DECL_VQ_NEARLOWDISK
122 # endif // VQ_NEARLOWDISK
123
124 # ifndef VQ_DESIRED_DISK
125 # undef HAVE_DECL_VQ_DESIRED_DISK
126 # endif // VQ_DESIRED_DISK
127
128 # if !defined(EVFILT_NW_CHANNEL) && defined(__APPLE__)
129 # define EVFILT_NW_CHANNEL (-16)
130 # define NOTE_FLOW_ADV_UPDATE 0x1
131 # endif
132 #else // DISPATCH_EVENT_BACKEND_KEVENT
133 # define EV_ADD 0x0001
134 # define EV_DELETE 0x0002
135 # define EV_ENABLE 0x0004
136
137 # define EV_ONESHOT 0x0010
138 # define EV_CLEAR 0x0020
139 # define EV_DISPATCH 0x0080
140
141 # define EVFILT_READ (-1)
142 # define EVFILT_WRITE (-2)
143 # define EVFILT_SIGNAL (-3)
144 # define EVFILT_TIMER (-4)
145 # define EVFILT_SYSCOUNT 4
146
147 # define DISPATCH_HAVE_TIMER_QOS 0
148 # define DISPATCH_HAVE_TIMER_COALESCING 0
149 # define KEVENT_FLAG_IMMEDIATE 0x001
150 #endif // !DISPATCH_EVENT_BACKEND_KEVENT
151
152 #ifdef EV_UDATA_SPECIFIC
153 # define DISPATCH_EV_DIRECT (EV_UDATA_SPECIFIC|EV_DISPATCH)
154 #else
155 # define DISPATCH_EV_DIRECT 0x0000
156 # define EV_UDATA_SPECIFIC 0x0000
157 # undef EV_VANISHED
158 # define EV_VANISHED 0x0000
159 #endif
160
161 #define DISPATCH_EV_MSG_NEEDS_FREE 0x10000 // mach message needs to be freed()
162
163 #define DISPATCH_EVFILT_TIMER (-EVFILT_SYSCOUNT - 1)
164 #define DISPATCH_EVFILT_CUSTOM_ADD (-EVFILT_SYSCOUNT - 2)
165 #define DISPATCH_EVFILT_CUSTOM_OR (-EVFILT_SYSCOUNT - 3)
166 #define DISPATCH_EVFILT_CUSTOM_REPLACE (-EVFILT_SYSCOUNT - 4)
167 #define DISPATCH_EVFILT_MACH_NOTIFICATION (-EVFILT_SYSCOUNT - 5)
168 #define DISPATCH_EVFILT_SYSCOUNT ( EVFILT_SYSCOUNT + 5)
169
170 #if HAVE_MACH
171 # if !EV_UDATA_SPECIFIC
172 # error mach support requires EV_UDATA_SPECIFIC
173 # endif
174
175 # ifndef MACH_RCV_VOUCHER
176 # define MACH_RCV_VOUCHER 0x00000800
177 # endif
178
179 # ifndef MACH_NOTIFY_SEND_POSSIBLE
180 # undef MACH_NOTIFY_SEND_POSSIBLE
181 # define MACH_NOTIFY_SEND_POSSIBLE MACH_NOTIFY_DEAD_NAME
182 # endif
183
184 # ifndef NOTE_MACH_CONTINUOUS_TIME
185 # define NOTE_MACH_CONTINUOUS_TIME 0
186 # endif // NOTE_MACH_CONTINUOUS_TIME
187
188 # ifndef HOST_NOTIFY_CALENDAR_SET
189 # define HOST_NOTIFY_CALENDAR_SET HOST_NOTIFY_CALENDAR_CHANGE
190 # endif // HOST_NOTIFY_CALENDAR_SET
191
192 # ifndef HOST_CALENDAR_SET_REPLYID
193 # define HOST_CALENDAR_SET_REPLYID 951
194 # endif // HOST_CALENDAR_SET_REPLYID
195
196 # ifndef MACH_SEND_OVERRIDE
197 # define MACH_SEND_OVERRIDE 0x00000020
198 typedef unsigned int mach_msg_priority_t;
199 # define MACH_MSG_PRIORITY_UNSPECIFIED ((mach_msg_priority_t)0)
200 # endif // MACH_SEND_OVERRIDE
201
202 # ifndef MACH_SEND_SYNC_OVERRIDE
203 # define MACH_SEND_SYNC_OVERRIDE 0x00100000
204 # endif // MACH_SEND_SYNC_OVERRIDE
205
206 # ifndef MACH_RCV_SYNC_WAIT
207 # define MACH_RCV_SYNC_WAIT 0x00004000
208 # endif // MACH_RCV_SYNC_WAIT
209
210 # define DISPATCH_MACH_TRAILER_SIZE sizeof(dispatch_mach_trailer_t)
211 # define DISPATCH_MACH_RCV_TRAILER MACH_RCV_TRAILER_CTX
212 # define DISPATCH_MACH_RCV_OPTIONS ( \
213 MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_LARGE_IDENTITY | \
214 MACH_RCV_TRAILER_ELEMENTS(DISPATCH_MACH_RCV_TRAILER) | \
215 MACH_RCV_TRAILER_TYPE(MACH_MSG_TRAILER_FORMAT_0) | \
216 MACH_RCV_VOUCHER)
217 #endif // HAVE_MACH
218
219 #endif // __DISPATCH_EVENT_EVENT_CONFIG__