2 * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
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.
27 #ifndef __DISPATCH_SOURCE_INTERNAL__
28 #define __DISPATCH_SOURCE_INTERNAL__
30 #ifndef __DISPATCH_INDIRECT__
31 #error "Please #include <dispatch/dispatch.h> instead of this file directly."
32 #include <dispatch/base.h> // for HeaderDoc
35 struct dispatch_source_vtable_s {
36 DISPATCH_VTABLE_HEADER(dispatch_source_s);
39 extern const struct dispatch_source_vtable_s _dispatch_source_kevent_vtable;
41 struct dispatch_kevent_s;
42 typedef struct dispatch_kevent_s *dispatch_kevent_t;
44 struct dispatch_timer_source_s {
49 uint64_t flags; // dispatch_timer_flags_t
52 struct dispatch_set_timer_params {
55 struct dispatch_timer_source_s values;
58 #define DSF_CANCELED 1u // cancellation has been requested
60 struct dispatch_source_s {
61 DISPATCH_STRUCT_HEADER(dispatch_source_s, dispatch_source_vtable_s);
62 DISPATCH_QUEUE_HEADER;
63 // Instruments always copies DISPATCH_QUEUE_MIN_LABEL_SIZE, which is 64,
64 // so the remainder of the structure must be big enough
66 char _ds_pad[DISPATCH_QUEUE_MIN_LABEL_SIZE];
69 dispatch_kevent_t ds_dkev;
71 dispatch_function_t ds_handler_func;
72 void *ds_handler_ctxt;
74 void *ds_cancel_handler;
76 unsigned int ds_is_level:1,
83 ds_handler_is_block:1;
85 unsigned int ds_atomic_flags;
87 unsigned long ds_data;
88 unsigned long ds_pending_data;
89 unsigned long ds_pending_data_mask;
91 TAILQ_ENTRY(dispatch_source_s) ds_list;
93 unsigned long ds_ident_hack;
95 struct dispatch_timer_source_s ds_timer;
101 void _dispatch_source_xref_release(dispatch_source_t ds);
102 dispatch_queue_t _dispatch_source_invoke(dispatch_source_t ds);
103 bool _dispatch_source_probe(dispatch_source_t ds);
104 void _dispatch_source_dispose(dispatch_source_t ds);
105 size_t _dispatch_source_debug(dispatch_source_t ds, char* buf, size_t bufsiz);
107 void _dispatch_source_kevent_resume(dispatch_source_t ds, uint32_t new_flags, uint32_t del_flags);
108 void _dispatch_kevent_merge(dispatch_source_t ds);
109 void _dispatch_kevent_release(dispatch_source_t ds);
110 void _dispatch_timer_list_update(dispatch_source_t ds);
112 struct dispatch_source_type_s {
115 bool (*init) (dispatch_source_t ds,
116 dispatch_source_type_t type,
122 #define DISPATCH_TIMER_INDEX_WALL 0
123 #define DISPATCH_TIMER_INDEX_MACH 1
125 #ifdef DISPATCH_NO_LEGACY
127 DISPATCH_TIMER_WALL_CLOCK = 0x4,
130 DISPATCH_TIMER_INTERVAL = 0x0,
131 DISPATCH_TIMER_ONESHOT = 0x1,
132 DISPATCH_TIMER_ABSOLUTE = 0x3,
135 DISPATCH_MACHPORT_DEAD = 0x1,
136 DISPATCH_MACHPORT_RECV = 0x2,
137 DISPATCH_MACHPORT_DELETED = 0x4,
142 extern const struct dispatch_source_type_s _dispatch_source_type_timer;
143 extern const struct dispatch_source_type_s _dispatch_source_type_read;
144 extern const struct dispatch_source_type_s _dispatch_source_type_write;
145 extern const struct dispatch_source_type_s _dispatch_source_type_proc;
146 extern const struct dispatch_source_type_s _dispatch_source_type_signal;
147 extern const struct dispatch_source_type_s _dispatch_source_type_vnode;
148 extern const struct dispatch_source_type_s _dispatch_source_type_vfs;
151 extern const struct dispatch_source_type_s _dispatch_source_type_mach_send;
152 extern const struct dispatch_source_type_s _dispatch_source_type_mach_recv;
155 extern const struct dispatch_source_type_s _dispatch_source_type_data_add;
156 extern const struct dispatch_source_type_s _dispatch_source_type_data_or;
158 #endif /* __DISPATCH_SOURCE_INTERNAL__ */