]> git.saurik.com Git - apple/libdispatch.git/blame - src/introspection_internal.h
libdispatch-913.30.4.tar.gz
[apple/libdispatch.git] / src / introspection_internal.h
CommitLineData
517da941
A
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
beb15981
A
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
41struct 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
53extern struct dispatch_introspection_state_s _dispatch_introspection;
517da941
A
54
55void _dispatch_introspection_init(void);
56void _dispatch_introspection_thread_add(void);
57dispatch_queue_t _dispatch_introspection_queue_create(dispatch_queue_t dq);
58void _dispatch_introspection_queue_dispose(dispatch_queue_t dq);
59void _dispatch_introspection_queue_item_enqueue(dispatch_queue_t dq,
60 dispatch_object_t dou);
61void _dispatch_introspection_queue_item_dequeue(dispatch_queue_t dq,
62 dispatch_object_t dou);
3e7be3d3 63void _dispatch_introspection_queue_item_complete(dispatch_object_t dou);
517da941
A
64void _dispatch_introspection_callout_entry(void *ctxt, dispatch_function_t f);
65void _dispatch_introspection_callout_return(void *ctxt, dispatch_function_t f);
66
beb15981
A
67#if DISPATCH_PURE_C
68
beb15981 69static dispatch_queue_t _dispatch_queue_get_current(void);
517da941
A
70
71DISPATCH_ALWAYS_INLINE
72static 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
81DISPATCH_ALWAYS_INLINE
82static 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
87DISPATCH_ALWAYS_INLINE
88static 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
beb15981
A
93void
94_dispatch_introspection_order_record(dispatch_queue_t top_q,
95 dispatch_queue_t bottom_q);
96
97void
98_dispatch_introspection_target_queue_changed(dispatch_queue_t dq);
99
100DISPATCH_ALWAYS_INLINE
101static inline void
6b746eb4 102_dispatch_introspection_sync_begin(dispatch_queue_t dq)
beb15981
A
103{
104 if (!_dispatch_introspection.debug_queue_inversions) return;
6b746eb4 105 _dispatch_introspection_order_record(dq, _dispatch_queue_get_current());
beb15981
A
106}
107
108#endif // DISPATCH_PURE_C
517da941 109
45201a42 110#else // DISPATCH_INTROSPECTION
517da941 111
beb15981
A
112#define DISPATCH_INTROSPECTION_QUEUE_HEADER
113#define DISPATCH_INTROSPECTION_QUEUE_HEADER_SIZE 0
517da941
A
114
115#define _dispatch_introspection_init()
116#define _dispatch_introspection_thread_add()
517da941
A
117
118DISPATCH_ALWAYS_INLINE
119static inline dispatch_queue_t
120_dispatch_introspection_queue_create(dispatch_queue_t dq) { return dq; }
121
122DISPATCH_ALWAYS_INLINE
123static inline void
124_dispatch_introspection_queue_dispose(dispatch_queue_t dq) { (void)dq; }
125
126DISPATCH_ALWAYS_INLINE
127static 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
132DISPATCH_ALWAYS_INLINE
133static inline void
134_dispatch_introspection_queue_push(dispatch_queue_t dq DISPATCH_UNUSED,
135 dispatch_object_t dou DISPATCH_UNUSED) {}
136
137DISPATCH_ALWAYS_INLINE
138static inline void
139_dispatch_introspection_queue_pop(dispatch_queue_t dq DISPATCH_UNUSED,
140 dispatch_object_t dou DISPATCH_UNUSED) {}
141
3e7be3d3
A
142DISPATCH_ALWAYS_INLINE
143static inline void
144_dispatch_introspection_queue_item_complete(
145 dispatch_object_t dou DISPATCH_UNUSED) {}
146
517da941
A
147DISPATCH_ALWAYS_INLINE
148static inline void
149_dispatch_introspection_callout_entry(void *ctxt DISPATCH_UNUSED,
150 dispatch_function_t f DISPATCH_UNUSED) {}
151
152DISPATCH_ALWAYS_INLINE
153static inline void
154_dispatch_introspection_callout_return(void *ctxt DISPATCH_UNUSED,
155 dispatch_function_t f DISPATCH_UNUSED) {}
156
beb15981
A
157DISPATCH_ALWAYS_INLINE
158static inline void
159_dispatch_introspection_target_queue_changed(
160 dispatch_queue_t dq DISPATCH_UNUSED) {}
161
162DISPATCH_ALWAYS_INLINE
163static inline void
6b746eb4 164_dispatch_introspection_sync_begin(dispatch_queue_t dq DISPATCH_UNUSED) {}
beb15981 165
517da941
A
166#endif // DISPATCH_INTROSPECTION
167
168#endif // __DISPATCH_INTROSPECTION_INTERNAL__