]> git.saurik.com Git - apple/libdispatch.git/blob - src/introspection_internal.h
libdispatch-913.20.5.tar.gz
[apple/libdispatch.git] / src / introspection_internal.h
1 /*
2 * Copyright (c) 2010-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_INTROSPECTION_INTERNAL__
28 #define __DISPATCH_INTROSPECTION_INTERNAL__
29
30 #if DISPATCH_INTROSPECTION
31
32 #define DISPATCH_INTROSPECTION_QUEUE_HEADER \
33 TAILQ_ENTRY(dispatch_queue_s) diq_list; \
34 dispatch_unfair_lock_s diq_order_top_head_lock; \
35 dispatch_unfair_lock_s diq_order_bottom_head_lock; \
36 TAILQ_HEAD(, dispatch_queue_order_entry_s) diq_order_top_head; \
37 TAILQ_HEAD(, dispatch_queue_order_entry_s) diq_order_bottom_head
38 #define DISPATCH_INTROSPECTION_QUEUE_HEADER_SIZE \
39 sizeof(struct { DISPATCH_INTROSPECTION_QUEUE_HEADER; })
40
41 struct dispatch_introspection_state_s {
42 TAILQ_HEAD(, dispatch_introspection_thread_s) threads;
43 TAILQ_HEAD(, dispatch_queue_s) queues;
44 dispatch_unfair_lock_s threads_lock;
45 dispatch_unfair_lock_s queues_lock;
46
47 ptrdiff_t thread_queue_offset;
48
49 // dispatch introspection features
50 bool debug_queue_inversions; // DISPATCH_DEBUG_QUEUE_INVERSIONS
51 };
52
53 extern struct dispatch_introspection_state_s _dispatch_introspection;
54
55 void _dispatch_introspection_init(void);
56 void _dispatch_introspection_thread_add(void);
57 dispatch_queue_t _dispatch_introspection_queue_create(dispatch_queue_t dq);
58 void _dispatch_introspection_queue_dispose(dispatch_queue_t dq);
59 void _dispatch_introspection_queue_item_enqueue(dispatch_queue_t dq,
60 dispatch_object_t dou);
61 void _dispatch_introspection_queue_item_dequeue(dispatch_queue_t dq,
62 dispatch_object_t dou);
63 void _dispatch_introspection_queue_item_complete(dispatch_object_t dou);
64 void _dispatch_introspection_callout_entry(void *ctxt, dispatch_function_t f);
65 void _dispatch_introspection_callout_return(void *ctxt, dispatch_function_t f);
66
67 #if DISPATCH_PURE_C
68
69 static dispatch_queue_t _dispatch_queue_get_current(void);
70
71 DISPATCH_ALWAYS_INLINE
72 static inline void
73 _dispatch_introspection_queue_push_list(dispatch_queue_t dq,
74 dispatch_object_t head, dispatch_object_t tail) {
75 struct dispatch_object_s *dou = head._do;
76 do {
77 _dispatch_introspection_queue_item_enqueue(dq, dou);
78 } while (dou != tail._do && (dou = dou->do_next));
79 };
80
81 DISPATCH_ALWAYS_INLINE
82 static inline void
83 _dispatch_introspection_queue_push(dispatch_queue_t dq, dispatch_object_t dou) {
84 _dispatch_introspection_queue_item_enqueue(dq, dou);
85 };
86
87 DISPATCH_ALWAYS_INLINE
88 static inline void
89 _dispatch_introspection_queue_pop(dispatch_queue_t dq, dispatch_object_t dou) {
90 _dispatch_introspection_queue_item_dequeue(dq, dou);
91 };
92
93 void
94 _dispatch_introspection_order_record(dispatch_queue_t top_q,
95 dispatch_queue_t bottom_q);
96
97 void
98 _dispatch_introspection_target_queue_changed(dispatch_queue_t dq);
99
100 DISPATCH_ALWAYS_INLINE
101 static inline void
102 _dispatch_introspection_sync_begin(dispatch_queue_t dq)
103 {
104 if (!_dispatch_introspection.debug_queue_inversions) return;
105 _dispatch_introspection_order_record(dq, _dispatch_queue_get_current());
106 }
107
108 #endif // DISPATCH_PURE_C
109
110 #else // DISPATCH_INTROSPECTION
111
112 #define DISPATCH_INTROSPECTION_QUEUE_HEADER
113 #define DISPATCH_INTROSPECTION_QUEUE_HEADER_SIZE 0
114
115 #define _dispatch_introspection_init()
116 #define _dispatch_introspection_thread_add()
117
118 DISPATCH_ALWAYS_INLINE
119 static inline dispatch_queue_t
120 _dispatch_introspection_queue_create(dispatch_queue_t dq) { return dq; }
121
122 DISPATCH_ALWAYS_INLINE
123 static inline void
124 _dispatch_introspection_queue_dispose(dispatch_queue_t dq) { (void)dq; }
125
126 DISPATCH_ALWAYS_INLINE
127 static inline void
128 _dispatch_introspection_queue_push_list(dispatch_queue_t dq DISPATCH_UNUSED,
129 dispatch_object_t head DISPATCH_UNUSED,
130 dispatch_object_t tail DISPATCH_UNUSED) {}
131
132 DISPATCH_ALWAYS_INLINE
133 static inline void
134 _dispatch_introspection_queue_push(dispatch_queue_t dq DISPATCH_UNUSED,
135 dispatch_object_t dou DISPATCH_UNUSED) {}
136
137 DISPATCH_ALWAYS_INLINE
138 static inline void
139 _dispatch_introspection_queue_pop(dispatch_queue_t dq DISPATCH_UNUSED,
140 dispatch_object_t dou DISPATCH_UNUSED) {}
141
142 DISPATCH_ALWAYS_INLINE
143 static inline void
144 _dispatch_introspection_queue_item_complete(
145 dispatch_object_t dou DISPATCH_UNUSED) {}
146
147 DISPATCH_ALWAYS_INLINE
148 static inline void
149 _dispatch_introspection_callout_entry(void *ctxt DISPATCH_UNUSED,
150 dispatch_function_t f DISPATCH_UNUSED) {}
151
152 DISPATCH_ALWAYS_INLINE
153 static inline void
154 _dispatch_introspection_callout_return(void *ctxt DISPATCH_UNUSED,
155 dispatch_function_t f DISPATCH_UNUSED) {}
156
157 DISPATCH_ALWAYS_INLINE
158 static inline void
159 _dispatch_introspection_target_queue_changed(
160 dispatch_queue_t dq DISPATCH_UNUSED) {}
161
162 DISPATCH_ALWAYS_INLINE
163 static inline void
164 _dispatch_introspection_sync_begin(dispatch_queue_t dq DISPATCH_UNUSED) {}
165
166 #endif // DISPATCH_INTROSPECTION
167
168 #endif // __DISPATCH_INTROSPECTION_INTERNAL__