2 * Copyright (c) 2008-2010 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_OBJECT_INTERNAL__
28 #define __DISPATCH_OBJECT_INTERNAL__
31 _DISPATCH_CONTINUATION_TYPE
= 0x00000, // meta-type for continuations
32 _DISPATCH_QUEUE_TYPE
= 0x10000, // meta-type for queues
33 _DISPATCH_SOURCE_TYPE
= 0x20000, // meta-type for sources
34 _DISPATCH_SEMAPHORE_TYPE
= 0x30000, // meta-type for semaphores
35 _DISPATCH_NODE_TYPE
= 0x40000, // meta-type for data node
36 _DISPATCH_IO_TYPE
= 0x50000, // meta-type for io channels
37 _DISPATCH_OPERATION_TYPE
= 0x60000, // meta-type for io operations
38 _DISPATCH_DISK_TYPE
= 0x70000, // meta-type for io disks
39 _DISPATCH_META_TYPE_MASK
= 0xfff0000, // mask for object meta-types
40 _DISPATCH_ATTR_TYPE
= 0x10000000, // meta-type for attributes
42 DISPATCH_CONTINUATION_TYPE
= _DISPATCH_CONTINUATION_TYPE
,
44 DISPATCH_DATA_TYPE
= _DISPATCH_NODE_TYPE
,
46 DISPATCH_IO_TYPE
= _DISPATCH_IO_TYPE
,
47 DISPATCH_OPERATION_TYPE
= _DISPATCH_OPERATION_TYPE
,
48 DISPATCH_DISK_TYPE
= _DISPATCH_DISK_TYPE
,
50 DISPATCH_QUEUE_ATTR_TYPE
= _DISPATCH_QUEUE_TYPE
|_DISPATCH_ATTR_TYPE
,
52 DISPATCH_QUEUE_TYPE
= 1 | _DISPATCH_QUEUE_TYPE
,
53 DISPATCH_QUEUE_GLOBAL_TYPE
= 2 | _DISPATCH_QUEUE_TYPE
,
54 DISPATCH_QUEUE_MGR_TYPE
= 3 | _DISPATCH_QUEUE_TYPE
,
55 DISPATCH_QUEUE_SPECIFIC_TYPE
= 4 | _DISPATCH_QUEUE_TYPE
,
57 DISPATCH_SEMAPHORE_TYPE
= _DISPATCH_SEMAPHORE_TYPE
,
59 DISPATCH_SOURCE_KEVENT_TYPE
= 1 | _DISPATCH_SOURCE_TYPE
,
62 #define DISPATCH_VTABLE_HEADER(x) \
63 unsigned long const do_type; \
64 const char *const do_kind; \
65 size_t (*const do_debug)(struct x *, char *, size_t); \
66 struct dispatch_queue_s *(*const do_invoke)(struct x *); \
67 bool (*const do_probe)(struct x *); \
68 void (*const do_dispose)(struct x *)
70 #define dx_type(x) (x)->do_vtable->do_type
71 #define dx_kind(x) (x)->do_vtable->do_kind
72 #define dx_debug(x, y, z) (x)->do_vtable->do_debug((x), (y), (z))
73 #define dx_dispose(x) (x)->do_vtable->do_dispose(x)
74 #define dx_invoke(x) (x)->do_vtable->do_invoke(x)
75 #define dx_probe(x) (x)->do_vtable->do_probe(x)
77 #define DISPATCH_STRUCT_HEADER(x, y) \
78 const struct y *do_vtable; \
79 struct x *volatile do_next; \
80 unsigned int do_ref_cnt; \
81 unsigned int do_xref_cnt; \
82 unsigned int do_suspend_cnt; \
83 struct dispatch_queue_s *do_targetq; \
87 #define DISPATCH_OBJECT_GLOBAL_REFCNT (~0u)
88 // "word and bit" must be a power of two to be safely subtracted
89 #define DISPATCH_OBJECT_SUSPEND_LOCK 1u
90 #define DISPATCH_OBJECT_SUSPEND_INTERVAL 2u
91 #define DISPATCH_OBJECT_SUSPENDED(x) \
92 ((x)->do_suspend_cnt >= DISPATCH_OBJECT_SUSPEND_INTERVAL)
94 // the bottom nibble must not be zero, the rest of the bits should be random
95 // we sign extend the 64-bit version so that a better instruction encoding is
97 #define DISPATCH_OBJECT_LISTLESS ((void *)0xffffffff89abcdef)
99 #define DISPATCH_OBJECT_LISTLESS ((void *)0x89abcdef)
102 struct dispatch_object_vtable_s
{
103 DISPATCH_VTABLE_HEADER(dispatch_object_s
);
106 struct dispatch_object_s
{
107 DISPATCH_STRUCT_HEADER(dispatch_object_s
, dispatch_object_vtable_s
);
110 size_t _dispatch_object_debug_attr(dispatch_object_t dou
, char* buf
,
113 void _dispatch_retain(dispatch_object_t dou
);
114 void _dispatch_release(dispatch_object_t dou
);
115 void _dispatch_dispose(dispatch_object_t dou
);
116 dispatch_queue_t
_dispatch_wakeup(dispatch_object_t dou
);