]> git.saurik.com Git - apple/libdispatch.git/blob - src/source_internal.h
libdispatch-913.1.6.tar.gz
[apple/libdispatch.git] / src / source_internal.h
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_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 enum {
36 /* DISPATCH_TIMER_STRICT 0x1 */
37 /* DISPATCH_TIMER_BACKGROUND = 0x2, */
38 DISPATCH_TIMER_CLOCK_MACH = 0x4,
39 DISPATCH_TIMER_INTERVAL = 0x8,
40 DISPATCH_TIMER_AFTER = 0x10,
41 /* DISPATCH_INTERVAL_UI_ANIMATION = 0x20 */
42 };
43
44 DISPATCH_ALWAYS_INLINE
45 static inline unsigned int
46 _dispatch_source_timer_idx(dispatch_unote_t du)
47 {
48 uint32_t clock, qos = 0, fflags = du._dt->du_fflags;
49
50 dispatch_assert(DISPATCH_CLOCK_MACH == 1);
51 dispatch_assert(DISPATCH_CLOCK_WALL == 0);
52 clock = (fflags & DISPATCH_TIMER_CLOCK_MACH) / DISPATCH_TIMER_CLOCK_MACH;
53
54 #if DISPATCH_HAVE_TIMER_QOS
55 dispatch_assert(DISPATCH_TIMER_STRICT == DISPATCH_TIMER_QOS_CRITICAL);
56 dispatch_assert(DISPATCH_TIMER_BACKGROUND == DISPATCH_TIMER_QOS_BACKGROUND);
57 qos = fflags & (DISPATCH_TIMER_STRICT | DISPATCH_TIMER_BACKGROUND);
58 // flags are normalized so this should never happen
59 dispatch_assert(qos < DISPATCH_TIMER_QOS_COUNT);
60 #endif
61
62 return DISPATCH_TIMER_INDEX(clock, qos);
63 }
64
65 #define _DISPATCH_SOURCE_HEADER(refs) \
66 DISPATCH_QUEUE_HEADER(refs); \
67 unsigned int \
68 ds_is_installed:1, \
69 dm_needs_mgr:1, \
70 dm_connect_handler_called:1, \
71 dm_uninstalled:1, \
72 dm_cancel_handler_called:1, \
73 dm_is_xpc:1
74
75 #define DISPATCH_SOURCE_HEADER(refs) \
76 struct dispatch_source_s _as_ds[0]; \
77 _DISPATCH_SOURCE_HEADER(refs)
78
79 DISPATCH_CLASS_DECL_BARE(source);
80 _OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(dispatch_source, dispatch_object);
81
82 #ifndef __cplusplus
83 struct dispatch_source_s {
84 _DISPATCH_SOURCE_HEADER(source);
85 uint64_t ds_data DISPATCH_ATOMIC64_ALIGN;
86 uint64_t ds_pending_data DISPATCH_ATOMIC64_ALIGN;
87 } DISPATCH_ATOMIC64_ALIGN;
88
89 // Extracts source data from the ds_data field
90 #define DISPATCH_SOURCE_GET_DATA(d) ((d) & 0xFFFFFFFF)
91
92 // Extracts status from the ds_data field
93 #define DISPATCH_SOURCE_GET_STATUS(d) ((d) >> 32)
94
95 // Combine data and status for the ds_data field
96 #define DISPATCH_SOURCE_COMBINE_DATA_AND_STATUS(data, status) \
97 ((((uint64_t)(status)) << 32) | (data))
98
99 #endif // __cplusplus
100
101 void _dispatch_source_refs_register(dispatch_source_t ds,
102 dispatch_wlh_t wlh, dispatch_priority_t bp);
103 void _dispatch_source_refs_unregister(dispatch_source_t ds, uint32_t options);
104 void _dispatch_source_xref_dispose(dispatch_source_t ds);
105 void _dispatch_source_dispose(dispatch_source_t ds, bool *allow_free);
106 void _dispatch_source_finalize_activation(dispatch_source_t ds,
107 bool *allow_resume);
108 void _dispatch_source_invoke(dispatch_source_t ds,
109 dispatch_invoke_context_t dic, dispatch_invoke_flags_t flags);
110 void _dispatch_source_wakeup(dispatch_source_t ds, dispatch_qos_t qos,
111 dispatch_wakeup_flags_t flags);
112 void _dispatch_source_merge_evt(dispatch_unote_t du, uint32_t flags,
113 uintptr_t data, uintptr_t status, pthread_priority_t pp);
114 size_t _dispatch_source_debug(dispatch_source_t ds, char* buf, size_t bufsiz);
115
116 DISPATCH_EXPORT // for firehose server
117 void _dispatch_source_merge_data(dispatch_source_t ds, pthread_priority_t pp,
118 unsigned long val);
119
120 void _dispatch_mgr_queue_push(dispatch_queue_t dq, dispatch_object_t dou,
121 dispatch_qos_t qos);
122 void _dispatch_mgr_queue_wakeup(dispatch_queue_t dq, dispatch_qos_t qos,
123 dispatch_wakeup_flags_t flags);
124 void _dispatch_mgr_thread(dispatch_queue_t dq, dispatch_invoke_context_t dic,
125 dispatch_invoke_flags_t flags);
126 #if DISPATCH_USE_KEVENT_WORKQUEUE
127 void _dispatch_kevent_worker_thread(dispatch_kevent_t *events,
128 int *nevents);
129 #endif // DISPATCH_USE_KEVENT_WORKQUEUE
130
131 #endif /* __DISPATCH_SOURCE_INTERNAL__ */