Tizen 2.1 base
[platform/upstream/gcd.git] / dispatch-1.0 / src / source_internal.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 /*
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_SOURCE_INTERNAL__
28 #define __DISPATCH_SOURCE_INTERNAL__
29
30 #ifndef __DISPATCH_INDIRECT__
31 #error "Please #include <dispatch/dispatch.h> instead of this file directly."
32 #include <dispatch/base.h> // for HeaderDoc
33 #endif
34
35 struct dispatch_source_vtable_s {
36         DISPATCH_VTABLE_HEADER(dispatch_source_s);
37 };
38
39 extern const struct dispatch_source_vtable_s _dispatch_source_kevent_vtable;
40
41 struct dispatch_kevent_s;
42 typedef struct dispatch_kevent_s *dispatch_kevent_t;
43
44 struct dispatch_timer_source_s {
45         uint64_t target;
46         uint64_t start;
47         uint64_t interval;
48         uint64_t leeway;
49         uint64_t flags; // dispatch_timer_flags_t
50 };
51
52 struct dispatch_set_timer_params {
53         dispatch_source_t ds;
54         uintptr_t ident;
55         struct dispatch_timer_source_s values;
56 };
57
58 #define DSF_CANCELED 1u // cancellation has been requested
59
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
65         union {
66                 char _ds_pad[DISPATCH_QUEUE_MIN_LABEL_SIZE];
67                 struct {
68                         char dq_label[8];
69                         dispatch_kevent_t ds_dkev;
70                         
71                         dispatch_function_t ds_handler_func;
72                         void *ds_handler_ctxt;
73                         
74                         void *ds_cancel_handler;
75                         
76                         unsigned int ds_is_level:1,
77                         ds_is_adder:1,
78                         ds_is_installed:1,
79                         ds_needs_rearm:1,
80                         ds_is_armed:1,
81                         ds_is_legacy:1,
82                         ds_cancel_is_block:1,
83                         ds_handler_is_block:1;
84
85                         unsigned int ds_atomic_flags;
86
87                         unsigned long ds_data;
88                         unsigned long ds_pending_data;
89                         unsigned long ds_pending_data_mask;
90                         
91                         TAILQ_ENTRY(dispatch_source_s) ds_list;
92                         
93                         unsigned long ds_ident_hack;
94                         
95                         struct dispatch_timer_source_s ds_timer;
96                 };
97         };
98 };
99
100
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);
106
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);
111
112 struct dispatch_source_type_s {
113         void *opaque;
114         uint64_t mask;
115         bool (*init) (dispatch_source_t ds,
116                       dispatch_source_type_t type,
117                       uintptr_t handle,
118                       unsigned long mask,
119                       dispatch_queue_t q);
120 };
121
122 #define DISPATCH_TIMER_INDEX_WALL 0
123 #define DISPATCH_TIMER_INDEX_MACH 1
124
125 #ifdef DISPATCH_NO_LEGACY
126 enum {
127         DISPATCH_TIMER_WALL_CLOCK       = 0x4,
128 };
129 enum {
130         DISPATCH_TIMER_INTERVAL = 0x0,
131         DISPATCH_TIMER_ONESHOT  = 0x1,
132         DISPATCH_TIMER_ABSOLUTE = 0x3,
133 };
134 enum {
135         DISPATCH_MACHPORT_DEAD = 0x1,
136         DISPATCH_MACHPORT_RECV = 0x2,
137         DISPATCH_MACHPORT_DELETED = 0x4,
138 };
139 #endif
140
141
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;
149
150 #if HAVE_MACH
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;
153 #endif
154
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;
157
158 #endif /* __DISPATCH_SOURCE_INTERNAL__ */